Javatpoint Logo
Javatpoint Logo

Uri.ReferenceEquals() Method in C#

In this article, we will discuss the Uri.ReferenceEquals() method in C# with its syntax, parameters, and examples.

What is the Uri.ReferenceEquals() method?

In C#, the Uri.ReferenceEquals() method is not a standard method provided by the .NET Framework's Uri class. The ReferenceEquals() method is a method from the C# Object class. It will give information on the Uri class.

The Uri class in C# belongs to the System namespace and represents a Uniform Resource Identifier (URI). It allows us to interpret, alter, and compare URIs easily. URIs can represent a variety of resources, including URLs and local file paths.


It has the following syntax:


uri_1: It is the initial URI to compare.

uri_2: It is an additional URI to compare.

Return Value:

This method gives a true value if two objects' references are equal; if not, it returns false.

Example 1:

Let us take an example to illustrate the Uri.ReferenceEquals() method in C#.


The null value is equal to the null

Example 2:

Let us take another example to illustrate the Uri.ReferenceEquals() method in C#.

Output: is not equal to is equal to is not equal to 

Advantages of the Uri.ReferenceEquals() Method

There are several advantages of the Uri.ReferenceEquals() Method in C#. Some main advantages of the Uri.ReferenceEquals() Method are as follows:

1. Reference comparison:

The programmers may use the ReferenceEquals() method to compare two objects at the reference level. It is useful for determining whether two variables reference the same object reference in memory.

2. Null Handling:

The ReferenceEquals() method handles null values effectively. If one or both of the items under comparison are null, the function returns true. It can make null-checking logic simpler in certain cases.

3. Performance:

Reference equality tests are quicker than value equality checks because they directly compare memory locations. The ReferenceEquals() method is a useful function for reference comparison in scenarios where speed is crucial.

4. Memory Management:

Effective memory management requires understanding reference equality. It assists developers in ensuring that they are dealing with the correct object instances, especially for cases involving object pooling or duplicating instances.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA