Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Uri.Compare Method (Uri, Uri, UriComponents, UriFormat, StringComparison)


Compares the specified parts of two URIs using the specified comparison rules.

Namespace:   System
Assembly:  System (in System.dll)

public static int Compare(
	Uri uri1,
	Uri uri2,
	UriComponents partsToCompare,
	UriFormat compareFormat,
	StringComparison comparisonType


Type: System.Uri

The first Uri.

Type: System.Uri

The second Uri.

Type: System.UriComponents

A bitwise combination of the UriComponents values that specifies the parts of uri1 and uri2 to compare.

Type: System.UriFormat

One of the UriFormat values that specifies the character escaping used when the URI components are compared.

Type: System.StringComparison

One of the StringComparison values.

Return Value

Type: System.Int32

An Int32 value that indicates the lexical relationship between the compared Uri components.



Less than zero

uri1 is less than uri2.


uri1 equals uri2.

Greater than zero

uri1 is greater than uri2.

Exception Condition

comparisonType is not a valid StringComparison value.

If both uri1 and uri2 are null, this method returns 0. When comparing URI values, a relative URI is always less than an absolute URI, and a non-null URI is always greater than a null URI. For cases where both uri1 and uri2 are not null and are both relative URIs or both absolute URIs, the String.Compare(String, String, StringComparison) method performs the comparison.

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft