C# Uri Equality

Description

Uri Equality determines whether two Uri instances have the same value.

Syntax

Uri.Equality has the following syntax.


public static bool operator ==(
  Uri uri1,
  Uri uri2
)

Parameters

Uri.Equality has the following parameters.

  • uri1 - A Uri instance to compare with uri2.
  • uri2 - A Uri instance to compare with uri1.

Returns

Uri.Equality method returns A Boolean value that is true if the Uri instances are equivalent; otherwise, false.

Example

This example creates three Uri instances from strings and compares them to determine whether they represent the same value. Address1 and Address2 are the same because the Fragment portion is ignored for this comparison. The outcome is written to the console.


//w w w . j a  va 2 s  .  com
using System;
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"); 
    Uri address3 = new Uri("http://www.java2s.com/index.htm?date=today"); 
    
    // The first two are equal because the fragment is ignored. 
    if (address1 == address2)
        Console.WriteLine("{0} is equal to {1}", address1.ToString(), address2.ToString());

  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version