TimeSpan.GetHashCode メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > TimeSpan.GetHashCode メソッドの意味・解説 

TimeSpan.GetHashCode メソッド

このインスタンスハッシュ コード返します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

2 つの TimeSpan オブジェクトが、異な時間値を表していても、同じハッシュ コードを持つ場合あります

使用例使用例

GetHashCode メソッド使用して複数TimeSpan オブジェクトハッシュ コード生成するコード例次に示します

' Example for the TimeSpan.GetHashCode( ) method.
Imports System
Imports Microsoft.VisualBasic

Module GetHashCode
    
    Sub DisplayHashCode( interval As TimeSpan
 )

        ' Create a hash code and a string representation of 
        ' the TimeSpan parameter.
        Dim timeInterval As String
 = interval.ToString( )
        Dim hashCode As Integer
 = interval.GetHashCode( )

        ' Pad the end of the TimeSpan string with spaces if it 
        ' does not contain milliseconds.
        Dim pIndex As Integer
 = timeInterval.IndexOf( ":"c )
        pIndex = timeInterval.IndexOf( "."c, pIndex
 )
        If pIndex < 0 Then timeInterval
 &= "        "

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

    Sub Main( )
        Console.WriteLine( _
            "This example of TimeSpan.GetHashCode( ) generates
 " & _
            "the following " & vbCrLf & "output,
 which displays " & _
            "the hash codes of representative TimeSpan "
 & vbCrLf & _
            "objects in hexadecimal and decimal formats."
 & vbCrLf )
        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 ) )
    End Sub
End Module 

' 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
// 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
*/ 
// Example for the TimeSpan::GetHashCode( ) method.
using namespace System;
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 = String::Concat( timeInterval, "        " );

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

int 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( TimeSpan(0) );
   DisplayHashCode( TimeSpan(1) );
   DisplayHashCode( TimeSpan(0,0,0,0,1) );
   DisplayHashCode( TimeSpan(0,0,1) );
   DisplayHashCode( TimeSpan(0,1,0) );
   DisplayHashCode( TimeSpan(1,0,0) );
   DisplayHashCode( TimeSpan(36000000001) );
   DisplayHashCode( TimeSpan(0,1,0,0,1) );
   DisplayHashCode( TimeSpan(1,0,1) );
   DisplayHashCode( TimeSpan(1,0,0,0) );
   DisplayHashCode( TimeSpan(864000000001) );
   DisplayHashCode( TimeSpan(1,0,0,0,1) );
   DisplayHashCode( TimeSpan(1,0,0,1) );
   DisplayHashCode( TimeSpan(100,0,0,0) );
   DisplayHashCode( TimeSpan(100,0,0,0,1) );
   DisplayHashCode( 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
*/
// Example for the TimeSpan.GetHashCode( ) method.
import 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}, {2}", timeInterval, 
            ((System.Int32)hashCode).ToString("X8"), String.valueOf(hashCode));
 
    } //DisplayHashCode

    public static void main(String[]
 args)
    {
        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(36000000001L));
        DisplayHashCode(new TimeSpan(0, 1, 0, 0, 1));
        DisplayHashCode(new TimeSpan(1, 0, 1));
        DisplayHashCode(new TimeSpan(1, 0, 0, 0));
        DisplayHashCode(new TimeSpan(864000000001L));
        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));
    } //main
} //GetHashCode

/*
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
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

TimeSpan.GetHashCode メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TimeSpan.GetHashCode メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS