当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C# Uri.Inequality()用法及代码示例


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

用法:

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

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

  • uri1:此参数是要比较的第一个 Uri。
  • uri2:此参数是要比较的第二个 Uri。

返回值:此方法返回布尔值。如果 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"); 
    } 
} 

输出:

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/



相关用法


注:本文由纯净天空筛选整理自SHUBHAMSINGH10大神的英文原创作品 Uri.Inequality() Operator in C# With Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。