Uri.Compare Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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

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


Public Shared Function Compare ( _
    uri1 As Uri, _
    uri2 As Uri, _
    partsToCompare As UriComponents, _
    compareFormat As UriFormat, _
    comparisonType As StringComparison _
) As Integer
public static int Compare(
    Uri uri1,
    Uri uri2,
    UriComponents partsToCompare,
    UriFormat compareFormat,
    StringComparison comparisonType


  • compareFormat
    Type: System..::.UriFormat
    One of the UriFormat values that specifies the character escaping used when the URI components are compared.

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 nullNothingnullptra null reference (Nothing in Visual Basic), 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 nullNothingnullptra null reference (Nothing in Visual Basic) and are both relative URIs or both absolute URIs, the String..::.Compare(String, String, StringComparison) method performs the comparison.

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0


Windows Phone

See Also


Uri Class

System Namespace