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
參考:
相關用法
- C# DateTimeOffset.Add()用法及代碼示例
- C# String.Contains()用法及代碼示例
- C# Math.Sin()用法及代碼示例
- C# Math.Cos()用法及代碼示例
- C# Dictionary.Add()用法及代碼示例
- C# Math.Tan()用法及代碼示例
- C# Math.Abs()方法用法及代碼示例
- C# Math.Exp()用法及代碼示例
- C# Math.Abs()函數用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 C# | Uri.GetHashCode() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。