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


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


Uri.GetHashCode()方法用于获取URI的哈希码。

用法: public override int GetHashCode ();

返回值:此方法返回一个Int32,其中包含为此URI生成的哈希值。


以下示例程序旨在说明Uri.GetHashCode()方法的使用:

示例1:

// C# program to demonstrate the 
// Uri.GetHashCode() Method 
using System; 
using System.Globalization; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
        // Declaring and initializing address1 
        string address1 = "http://www.contoso.com/index.htm#search"; 
  
        // Getting HashCode by 
        // using GetHashCode() method 
        int value = address1.GetHashCode(); 
  
        // Displaying the result 
        Console.WriteLine("HashCode is : {0}", value); 
    } 
}
输出:
HashCode is : 2065713268

示例2:

// C# program to demonstrate the 
// Uri.GetHashCode() Method 
using System; 
using System.Globalization; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
  
        // calling get() method 
        get(new Uri("http://www.contoso.com")); 
        get(new Uri("http://www.google.com")); 
    } 
  
    // defining get() method 
    public static void get(Uri address1) 
    { 
  
        // Getting HashCode by 
        // using GetHashCode() method 
        int value = address1.GetHashCode(); 
  
        // Displaying the result 
        Console.WriteLine("HashCode is : {0}", value); 
    } 
}
输出:
HashCode is : 2014
HashCode is : 1498

参考:



相关用法


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