此方法用於返回此實例的哈希碼。
用法: 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#。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。