此方法用于返回此实例的哈希码。
用法: public override int GetHashCode ();
返回值:此方法返回32位有符号整数哈希码。
以下示例程序旨在说明DateTime.GetHashCode()方法的使用:
示例1:
// C# program to demonstrate the
// DateTime.GetHashCode()
// Method
using System;
class GFG {
// Main Method
public static void Main()
{
// creating object of DateTime
DateTime date = new DateTime(2010, 1,
1, 4, 0, 15);
// getting hashcode from DateTime
// using GetHashCode() method;
int value = date.GetHashCode();
// Display the hashcode
Console.WriteLine("hashcode is {0}", value);
}
}
输出:
hashcode is 103491886
示例2:
// C# program to demonstrate the
// DateTime.GetHashCode()
// Method
using System;
class GFG {
// Main Method
public static void Main()
{
// calling check() method
check(new DateTime(2010, 1,
3, 4, 0, 15));
check(new DateTime(2010, 1,
5, 4, 0, 15));
}
public static void check(DateTime date)
{
// getting HashCode from DateTime
// using GetHashCode() method;
int value = date.GetHashCode();
// Display the ShortTime
Console.WriteLine("HashCode of {0} is {1}",
date, value);
}
}
输出:
HashCode of 01/03/2010 04:00:15 is 1802939328 HashCode of 01/05/2010 04:00:15 is -1337841070
参考:
相关用法
注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 DateTime.GetHashCode() Method in C#。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。