Open In App

Uri.Inequality() Operator in C# With Examples

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

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 not equivalent, otherwise false.

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

Example 1:




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

Output:

address1 is Equals to address2

Example 2:




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

Output:

http://www.gfg.com/ is Equals to http://www.gfg.com/
http://www.abcd.com/ is not Equals to https://www.geeksforgeeks.org/

Article Tags :
C#