當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


C# DateTimeOffset.GetHashCode用法及代碼示例


DateTimeOffset.GetHashCode方法用於獲取當前DateTimeOffset對象的哈希碼。

用法: public override int GetHashCode ();

返回值:此方法返回32位有符號整數哈希碼。


以下示例程序旨在說明DateTimeOffset.GetHashCode()方法的使用:

範例1:

// C# program to demonstrate the 
// DateTimeOffset.GetHashCode() 
// Method 
using System; 
using System.Globalization; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
  
        // creating object of  DateTimeOffset 
        DateTimeOffset offset = new DateTimeOffset(2007, 
                6, 1, 7, 55, 0, new TimeSpan(-5, 0, 0)); 
  
        // Returns the hash code for the 
        // current DateTimeOffset object. 
        // instance using GetHashCode() method 
        int value = offset.GetHashCode(); 
  
        // Display the HashCode 
        Console.WriteLine("HashCode for DateTimeOffset is:{0}", value); 
    } 
}
輸出:
HashCode for DateTimeOffset is:981031011

範例2:

// C# program to demonstrate the 
// DateTimeOffset.GetHashCode() 
// Method 
using System; 
using System.Globalization; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
        // calling get() Method 
        get(new DateTimeOffset(2007, 6, 1, 7,  
             55, 0, new TimeSpan(-5, 0, 0))); 
                      
        get(new DateTimeOffset(2017, 6, 1, 7, 
             55, 0, new TimeSpan(-5, 0, 0))); 
    } 
    public static void get(DateTimeOffset offset) 
    { 
  
        // Returns the hash code for the  
        // current DateTimeOffset object. 
        // instance using GetHashCode() method 
        int value = offset.GetHashCode(); 
  
        // Display the HashCode 
        Console.WriteLine("HashCode for DateTimeOffset is:{0}", value); 
    } 
}
輸出:
HashCode for DateTimeOffset is:981031011
HashCode for DateTimeOffset is:1633960685


相關用法


注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 DateTimeOffset.GetHashCode Method in C#。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。