Uri.Equality() Operator in C# with Examples

Uri.Equality() Operator is used to compare two Uri objects.  If two Uri objects contain the same Uri, then it returns the true otherwise it returns false

Syntax: 

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

Parameter: This method has the following parameters:

uri1: This parameter is the first Uri to be compared.

uri2: This parameter is the second Uri to be compared.

Return Value: This method returns the Boolean value. It returns the true if the Uri instances are equivalent, otherwise false.



Below programs illustrate the use of Uri.Equality() Operator:

Example 1:

C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the 
// Uri.Equality() Operator
  
using System;  
    
class GFG { 
    
    // Main Method 
    public static void Main() 
    
        // Declaring and initializing address1 
        Uri address1 = new Uri("http://www.abcs.com/index.htm#search"); 
    
        // Declaring and intializing address2 
        Uri address2 = new Uri("http://www.abcd.com/index.htm"); 
    
        // Comparing both instance 
        // using Uri.Equality() Operator
        if (address1 == address2)
            Console.WriteLine("address1 is Equals to address2"); 
        else
            Console.WriteLine("address1 is not Equals to address2"); 
    
}

chevron_right


Output

address1 is not Equals to address2

Example 2:

C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the 
// Uri.Equality() Operator
  
using System;  
    
class GFG { 
      
    // defining get_equality() method 
    public static void get_equality(Uri address1, 
                           Uri address2) 
    
    
        // Comparing both instance 
        // using Uri.Equality() Operator
        if (address1 == address2) 
            Console.WriteLine("{0} is Equals to {1}", address1, address2); 
        else
            Console.WriteLine("{0} is not Equals to {1}", address1, address2); 
    
    
    // Main Method 
    public static void Main() 
    
        // calling get_equality() method 
        get_equality(new Uri("http://www.abcd.com"), 
            new Uri("http://www.abcd.com")); 
    
        get_equality(new Uri("http://www.google.com"),  
            new Uri("http://www.facebook.com"));  
    
}

chevron_right


Output

http://www.abcd.com/ is Equals to http://www.abcd.com/
http://www.google.com/ is not Equals to http://www.facebook.com/



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.