當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。