Uri.ReferenceEquals() Method in C# with Examples

Uri.ReferenceEquals() Method is used to check the reference of two specified objects. This method can be overridden and static in nature. So, if a user is going to test the two objects references for equality and he is not sure about the implementation of the Equals method, then he can call the ReferenceEquals method.

Syntax: bool Uri.ReferenceEquals (Uri uri1, Uri uri2);

Parameters:
uri1: It is the first uri to compare.
uri2: It is the second uri to compare.

Return Value: This method returns true if reference of two objects are equal otherwise it returns false.

Below programs illustrate the use of Uri.ReferenceEquals()  Method:

Example 1:



C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the 
// Uri.ReferenceEquals() Method 
using System; 
using System.Globalization; 
    
class GFG { 
    
     // Main Method 
    public static void Main() 
    
        // Declaring and initializing value1 
        Uri  v1 = null
    
        // Declaring and initializing value2 
        Uri  v2 = null
    
        // using ReferenceEquals(Uri , 
        // Uri ) method 
        bool status = Uri.ReferenceEquals(v1, v2); 
    
        // checking the status 
        if (status) 
            Console.WriteLine("null is equal to null"); 
        else
            Console.WriteLine("null is not equal to null"); 
    
}

chevron_right


Output:

null is equal to null

Example 2:

C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the 
// Uri.ReferenceEquals() Method 
using System; 
using System.Globalization; 
    
class GFG { 
    
    // Main Method 
    public static void Main() 
    
    
        Uri  p = new Uri("http://www.geeksforgeeks.org/index.htm"); 
        Uri  q = null
    
        // calling get() method 
        get(p, null); 
    
        // assigning p to q 
        q = p; 
        get(p, q); 
        get(q, null); 
    
    
    // defining get() method 
    public static void get(Uri  v1, 
                           Uri  v2) 
    
    
        // using ReferenceEquals() method 
        bool status = Uri.ReferenceEquals(v1, v2); 
    
        // checking the status 
        if (status) 
            Console.WriteLine("{0} is equal to {1}"
                                            v1, v2); 
        else
            Console.WriteLine("{0} is not equal to {1}"
                                                v1, v2); 
    
}

chevron_right


Output:

http://www.geeksforgeeks.org/index.htm is not equal to 
http://www.geeksforgeeks.org/index.htm is equal to http://www.geeksforgeeks.org/index.htm
http://www.geeksforgeeks.org/index.htm is not equal to 

Note: Here, null will never be printed in the output.




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.