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


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


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

用法:

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

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

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

返回值:此方法返回布尔值。它返回真实如果 Uri 实例相等,否则为 false。



以下示例程序旨在说明使用Uri.Equality() 运算符:

范例1:

C#


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

范例2:

C#


// C# program to demonstrate the 
// Uri.Equality() Operator
  
using System;  
    
class GFG { 
      
    // defining get_equality() method 
    public static void get_equality(Uri address1, 
                           Uri address2) 
    { 
    
        // Comparing both instance 
        // using Uri.Equality() Operator
        if (address1 == address2) 
            Console.WriteLine("{0} is Equals to {1}", address1, address2); 
        else
            Console.WriteLine("{0} is not Equals to {1}", address1, address2); 
    } 
    
    // Main Method 
    public static void Main() 
    { 
        // calling get_equality() method 
        get_equality(new Uri("http://www.abcd.com"), 
            new Uri("http://www.abcd.com")); 
    
        get_equality(new Uri("http://www.google.com"),  
            new Uri("http://www.facebook.com"));  
    } 
}
输出
http://www.abcd.com/ is Equals to http://www.abcd.com/
http://www.google.com/ is not Equals to http://www.facebook.com/



相关用法


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