Double.GetHashCode()方法用于返回此实例的哈希码。
Syntax: public override int GetHashCode ();
Return Value: This method returns a 32-bit signed integer hash code.
下面的程序说明了Double.GetHashCode()方法的用法:
范例1:
// C# program to demonstrate the
// Double.GetHashCode() Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing value1
double value1 = 10d;
// getting the HashCode
// using GetHashCode() method
int value = value1.GetHashCode();
// Display the HashCode
Console.WriteLine("HashCode is {0}", value);
}
}
输出:
HashCode is 1076101120
范例2:
// C# program to demonstrate the
// Double.Equals(Double)
// Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// calling get() method
get(5d);
get(5.5d);
get(10d);
get(7.5d);
}
// defining get() method
public static void get(double value1)
{
// getting the HashCode
// using GetHashCode() method
int value = value1.GetHashCode();
// Display the HashCode
Console.WriteLine("HashCode is {0}", value);
}
}
输出:
HashCode is 1075052544
HashCode is 1075183616
HashCode is 1076101120
HashCode is 1075707904
参考:
- https://docs.microsoft.com/zh-cn/dotnet/api/system.double.gethashcode?view=netframework-4.7.2