C# Uri Compare

In this chapter you will learn:

  1. Get to know Uri.Compare
  2. Syntax for Uri.Compare
  3. Parameter for Uri.Compare
  4. Returns for Uri.Compare
  5. Example - Uri.Compare

Description

Uri Compare compares the specified parts of two URIs using the specified comparison rules.

Syntax

Uri.Compare has the following syntax.


public static int Compare(
  Uri uri1,//from  www.  j a v a  2  s.  c om
  Uri uri2,
  UriComponents partsToCompare,
  UriFormat compareFormat,
  StringComparison comparisonType
)

Parameters

Uri.Compare has the following parameters.

  • uri1 - The first Uri.
  • uri2 - The second Uri.
  • partsToCompare - A bitwise combination of the UriComponents values that specifies the parts of uri1 and uri2 to compare.
  • compareFormat - One of the UriFormat values that specifies the character escaping used when the URI components are compared.
  • comparisonType - One of the StringComparison values.

Returns

Uri.Compare method returns An Int32 value that indicates the lexical relationship between the compared Uri components. Value Meaning Less than zero uri1 is less than uri2. Zero uri1 equals uri2. Greater than zero uri1 is greater than uri2.

Example


using System;/*from ww w .ja v a 2s  . c  o m*/
public class MainClass{
  public static void Main(String[] argv){  
    // Create some Uris.
    Uri address1 = new Uri("http://www.java2s.com/index.htm#search");
    Uri address2 = new Uri("http://www.java2s.com/index.htm"); 
    Console.WriteLine(Uri.Compare(address2,address1,null,null,null));
  }
}

Next chapter...

What you will learn in the next chapter:

  1. Get to know Uri.Equals
  2. Syntax for Uri.Equals
  3. Parameter for Uri.Equals
  4. Returns for Uri.Equals
  5. Example - Uri.Equals