📜  C#中的Uri.Inequality()运算符与示例

📅  最后修改于: 2021-05-29 16:47:31             🧑  作者: Mango

Uri.Inequality()运算符用于比较两个Uri对象。如果两个Uri对象包含相同的Uri,则返回false,否则返回true

句法:

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

参数:此方法具有以下参数:

返回值:该方法返回布尔值。如果Uri实例不相等,则返回true,否则返回false。

下面的程序说明了Uri.Inequality()运算符的用法:

范例1:

C#
// 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 intializing 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"); 
    } 
}


C#
// 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("http://www.geeksforgeeks.org"));  
    } 
}


输出:

address1 is Equals to address2

范例2:

C#

// 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("http://www.geeksforgeeks.org"));  
    } 
} 

输出:

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