Uri.GetHashCode()方法用于获取URI的哈希码。
Syntax: public override int GetHashCode ();
Return Value: This method returns an Int32 containing the hash value generated for this 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
参考:
- https://docs.microsoft.com/zh-cn/dotnet/api/system.uri.gethashcode?view=netstandard-2.1