Home » C#

C# | Uri.Equality() Operator with Example

Uri.Equality() Operator: Here, we are going to learn about the Equality() Operator of Uri class with example in C#.
Submitted by Nidhi, on March 26, 2020

Uri.Equality() Operator

Uri.Equality() Operator is overloaded which is used to compare two Uri objects. It returns true if two Uri objects contain the same Uri otherwise it returns false.


    bool operator == (Uri uri1, Uri uri2);


  • Uri uri1 – represents the first Uri to be compared.
  • Uri uri2 – represents the second Uri to be compared.

Return value:

The return type of this method is Boolean, it returns true if the Uri instances are the same; otherwise, false.

Example to demonstrate example of Uri.Equality() Operator

using System;

class UriExample
    //Entry point of Program
    static public void Main()
        // Create some Uri objects
        Uri uri1 = new Uri("https://www.includehelp.com/");
        Uri uri2 = new Uri("https://www.includehelp.com/");
        Uri uri3 = new Uri("https://www.includehelp.com/index.html");

        if (uri1 == uri2)
            Console.WriteLine("uri1 and uri2 are equal");
            Console.WriteLine("uri1 and uri2 are not equal");

        if (uri1 == uri3)
            Console.WriteLine("uri1 and uri3 are equal");
            Console.WriteLine("uri1 and uri3 are not equal");


uri1 and uri2 are equal
uri1 and uri3 are not equal

Reference: Uri.Equality(Uri, Uri) Operator

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.