Comparing two URIs can be done with [System.Uri.Compare](https://msdn.microsoft.com/en-us/library/system.uri.compare(v=vs.110).aspx).  

However, comparing `http://example.com/pages?pageStart=100&pageSize=50` with `http://example.com/pages?pageSize=50&pageStart=100` says the two URIs are different. Is there any way to make the comparison ignore the order in which values appear within the querystring; as functionally the two URIs are identical.

I'm thinking of writing a wrapper method to put the query-string parameters in order before calling the standard compare function, but wanted to check first whether there was an out of the box solution, as it seems odd that the comparison wouldn't already have an option for this.

---

**Update**

This is the solution I've come up with for comparing two URIs, regardless or their querystring parameter order. As mentioned above, this does it by first sorting the querystring of each URI. However, if there's an existing solution within .net I'd rather drop my code & use that.

```powershell
function CompareUri ($GivenUri, $ShouldBeUri) {
    $uriComponentsOptions = ([UriComponents]::AbsoluteUri)
    $uriFormatOptions = ([UriFormat]::SafeUnescaped)
    $stringComparisonOptions = ([StringComparison]::OrdinalIgnoreCase)
    $a = OrderUriQueryString($GivenUri)
    $b = OrderUriQueryString($ShouldBeUri)
    [Uri]::Compare($a, $b, $uriComponentsOptions, $uriFormatOptions, $stringComparisonOptions)
}

function OrderUriQueryString($Uri) {
    [System.UriBuilder]$UriBuilder = New-Object -TypeName 'System.UriBuilder' -ArgumentList $Uri
    [System.Collections.Specialized.NameValueCollection]$Query = [System.Web.HttpUtility]::ParseQueryString($UriBuilder.Query)
    [System.Collections.Specialized.NameValueCollection]$Query2 = [System.Web.HttpUtility]::ParseQueryString('') #we have to initialise this way as HttpValueCollection has no public constructor (https://referencesource.microsoft.com/#system.web/HttpValueCollection.cs,fde6b9ec5f1ed58a,references)  
    $Query.AllKeys | sort | %{ $Query2.Add($_, $Query[$_]) }
    $UriBuilder.Query = $Query2.ToString()
    $UriBuilder.ToString()
}

```