Uri.Equals(Object) Method in C#


The Uri.Equals() method in C# compares two Uri instances for equality.

Syntax

Following is the syntax −

public override bool Equals (object comparand);

Above, the parameter comparand is the Uri instance or a URI identifier to compare with the current instance.

Example

Let us now see an example to implement the Uri.Equals() method −

using System;
public class Demo {
   public static void Main(){
      Uri newURI1 = new Uri("https://www.tutorialspoint.com/index.htm");
      Console.WriteLine("URI = "+newURI1);
      Uri newURI2 = new Uri("https://www.tutorialspoint.com/index.htm");
      Console.WriteLine("URI = "+newURI2);
      if(newURI1.Equals(newURI2))
         Console.WriteLine("Both the URIs are equal!");
      else
         Console.WriteLine("Both the URIs aren't equal!");
   }
}

Output

This will produce the following output −

URI = https://www.tutorialspoint.com/index.htm
URI = http://www.tutorialspoint.com/index.htm
Both the URIs aren't equal!

Example

Let us now see another example to implement the Uri.Equals() method −

using System;
public class Demo {
   public static void Main(){
      Uri newURI1 = new Uri("https://www.tutorialspoint.com/index.htm");
      Console.WriteLine("URI = "+newURI1);
      Uri newURI2 = new Uri("https://www.tutorialspoint.com/");
      Console.WriteLine("URI = "+newURI2);
      if(newURI1.Equals(newURI2))
         Console.WriteLine("Both the URIs are equal!");
      else
         Console.WriteLine("Both the URIs aren't equal!");
   }
}

Output

This will produce the following output −

URI = https://www.tutorialspoint.com/index.htm
URI = https://www.tutorialspoint.com/
Both the URIs aren't equal!

Updated on: 13-Nov-2019

49 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements