Int64.GetHashCode方法用于获取当前Int64实例的HashCode。
Syntax: public override int GetHashCode ();
Return Value: This method returns a 32-bit signed integer hash code.
下面的程序说明了上面讨论的方法的使用:
范例1:
// C# program to illustrate the
// Int64.GetHashCode() Method
using System;
class GFG {
// Main Method
public static void Main()
{
// Taking Int64 variable
// i.e. long data type
long s1 = 458732523;
// Getting the hash code for Int64
// using GetHashCode() method
int result = s1.GetHashCode();
// Display the HashCode
Console.WriteLine("HashCode for Int64 is: {0}",
result);
}
}
输出:
HashCode for Int64 is: 458732523
范例2:
// C# program to illustrate the
// Int64.GetHashCode() Method
using System;
class GFG {
// Main Method
public static void Main()
{
// using result() Method
result(Int64.MinValue);
result(Int64.MaxValue);
}
// result() method
public static void result(long val)
{
// using GetHashCode() method
int code = val.GetHashCode();
// Display the hashcode
Console.WriteLine("HashCode for {0} is {1}",
val, code);
}
}
输出:
HashCode for -9223372036854775808 is -2147483648
HashCode for 9223372036854775807 is -2147483648
参考:
- https://docs.microsoft.com/zh-cn/dotnet/api/system.int64.gethashcode?view=netframework-4.7.2