當前位置: 首頁>>代碼示例>>C#>>正文


C# TimeSpan.GetHashCode方法代碼示例

本文整理匯總了C#中System.TimeSpan.GetHashCode方法的典型用法代碼示例。如果您正苦於以下問題:C# TimeSpan.GetHashCode方法的具體用法?C# TimeSpan.GetHashCode怎麽用?C# TimeSpan.GetHashCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.TimeSpan的用法示例。


在下文中一共展示了TimeSpan.GetHashCode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DisplayHashCode

// Example for the TimeSpan.GetHashCode( ) method.
using System;

class GetHashCode
{
    static void DisplayHashCode( TimeSpan interval )
    {
        // Create a hash code and a string representation of 
        // the TimeSpan parameter.
        string  timeInterval = interval.ToString( );
        int     hashCode = interval.GetHashCode( );

        // Pad the end of the TimeSpan string with spaces if it 
        // does not contain milliseconds.
        int pIndex = timeInterval.IndexOf( ':' );
        pIndex = timeInterval.IndexOf( '.', pIndex );
        if( pIndex < 0 )   timeInterval += "        ";

        Console.WriteLine( "{0,22}   0x{1:X8}, {1}", 
            timeInterval, hashCode );
    }

    static void Main( )
    {
        Console.WriteLine(
            "This example of TimeSpan.GetHashCode( ) generates " +
            "the following \noutput, which displays " +
            "the hash codes of representative TimeSpan \n" +
            "objects in hexadecimal and decimal formats.\n" );
        Console.WriteLine( "{0,22}   {1,10}", 
            "TimeSpan        ", "Hash Code" );
        Console.WriteLine( "{0,22}   {1,10}", 
            "--------        ", "---------" );

        DisplayHashCode( new TimeSpan( 0 ) );
        DisplayHashCode( new TimeSpan( 1 ) );
        DisplayHashCode( new TimeSpan( 0, 0, 0, 0, 1 ) );
        DisplayHashCode( new TimeSpan( 0, 0, 1 ) );
        DisplayHashCode( new TimeSpan( 0, 1, 0 ) );
        DisplayHashCode( new TimeSpan( 1, 0, 0 ) );
        DisplayHashCode( new TimeSpan( 36000000001 ) );
        DisplayHashCode( new TimeSpan( 0, 1, 0, 0, 1 ) );
        DisplayHashCode( new TimeSpan( 1, 0, 1 ) );
        DisplayHashCode( new TimeSpan( 1, 0, 0, 0 ) );
        DisplayHashCode( new TimeSpan( 864000000001 ) );
        DisplayHashCode( new TimeSpan( 1, 0, 0, 0, 1 ) );
        DisplayHashCode( new TimeSpan( 1, 0, 0, 1 ) );
        DisplayHashCode( new TimeSpan( 100, 0, 0, 0 ) );
        DisplayHashCode( new TimeSpan( 100, 0, 0, 0, 1 ) );
        DisplayHashCode( new TimeSpan( 100, 0, 0, 1 ) );
    } 
} 

/*
This example of TimeSpan.GetHashCode( ) generates the following
output, which displays the hash codes of representative TimeSpan
objects in hexadecimal and decimal formats.

      TimeSpan            Hash Code
      --------            ---------
      00:00:00           0x00000000, 0
      00:00:00.0000001   0x00000001, 1
      00:00:00.0010000   0x00002710, 10000
      00:00:01           0x00989680, 10000000
      00:01:00           0x23C34600, 600000000
      01:00:00           0x61C46808, 1640261640
      01:00:00.0000001   0x61C46809, 1640261641
      01:00:00.0010000   0x61C48F18, 1640271640
      01:00:01           0x625CFE88, 1650261640
    1.00:00:00           0x2A69C0C9, 711573705
    1.00:00:00.0000001   0x2A69C0C8, 711573704
    1.00:00:00.0010000   0x2A69E7D9, 711583705
    1.00:00:01           0x2B025649, 721573449
  100.00:00:00           0x914F4E94, -1857073516
  100.00:00:00.0010000   0x914F6984, -1857066620
  100.00:00:01           0x91E7D814, -1847076844
*/
開發者ID:.NET開發者,項目名稱:System,代碼行數:77,代碼來源:TimeSpan.GetHashCode


注:本文中的System.TimeSpan.GetHashCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。