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

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

String.GetHashCode メソッド

この文字列ハッシュ コード返します

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

解説解説

GetHashCode動作実装依存します。この実装は、共通言語ランタイムのあるバージョンから別のバージョン変更される可能性ありますGetHashCodeパフォーマンス向上がその理由です。GetHashCode動作一定にする必要がある場合は、GetHashCodeランタイムによる実装を、変更されないことがわかっている独自の実装オーバーライドしてください

使用例使用例

さまざまな入力文字列使用する GetHashCode メソッドコード例次に示します

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

Module GetHashCode
   
    Sub Main()
        Console.WriteLine( _
            "This example of String.GetHashCode( ) "
 & _
            "generates the following output." &
 vbCrLf)

        DisplayHashCode("")
        DisplayHashCode("a")
        DisplayHashCode("ab")
        DisplayHashCode("abc")
        DisplayHashCode("abd")
        DisplayHashCode("abe")
        DisplayHashCode("abcdef")
        DisplayHashCode("abcdeg")
        DisplayHashCode("abcdeh")
        DisplayHashCode("abcdei")
        DisplayHashCode("Abcdeg")
        DisplayHashCode("Abcdeh")
        DisplayHashCode("Abcdei")
    End Sub 'Main
       
    Sub DisplayHashCode(Operand As String)

        Dim HashCode As Integer
 = Operand.GetHashCode()
        Console.WriteLine( _
            "The hash code for ""{0}""
 is: 0x{1:X8}, {1}", _
            Operand, HashCode)

    End Sub 'DisplayHashCode
End Module 'GetHashCode

' This example of String.GetHashCode( ) generates the following output.
' 
' The hash code for "" is: 0x00001505, 5381
' The hash code for "a" is: 0x0002B5C4, 177604
' The hash code for "ab" is: 0x00596E26, 5860902
' The hash code for "abc" is: 0x0B873285, 193409669
' The hash code for "abd" is: 0x0B873282, 193409666
' The hash code for "abe" is: 0x0B873283, 193409667
' The hash code for "abcdef" is: 0x4DDB4BE2, 1306217442
' The hash code for "abcdeg" is: 0x4DDB4BE3, 1306217443
' The hash code for "abcdeh" is: 0x4DDB4BEC, 1306217452
' The hash code for "abcdei" is: 0x4DDB4BED, 1306217453
' The hash code for "Abcdeg" is: 0x941C4FC3, -1810083901
' The hash code for "Abcdeh" is: 0x941C4FCC, -1810083892
' The hash code for "Abcdei" is: 0x941C4FCD, -1810083891
// Example for the String.GetHashCode( ) method.
using System;

class GetHashCode 
{
    public static void Main()
 
    {
        Console.WriteLine( 
            "This example of String.GetHashCode( ) " +
            "generates the following output.\n" );

        DisplayHashCode( "" );
        DisplayHashCode( "a" );
        DisplayHashCode( "ab" );
        DisplayHashCode( "abc" );
        DisplayHashCode( "abd" );
        DisplayHashCode( "abe" );
        DisplayHashCode( "abcdef" );
        DisplayHashCode( "abcdeg" );
        DisplayHashCode( "abcdeh" );
        DisplayHashCode( "abcdei" );
        DisplayHashCode( "Abcdeg" );
        DisplayHashCode( "Abcdeh" );
        DisplayHashCode( "Abcdei" );
    }

    static void DisplayHashCode( String Operand
 )
    {
        int     HashCode = Operand.GetHashCode( );
        Console.WriteLine( 
            "The hash code for \"{0}\" is: 0x{1:X8},
 {1}",
            Operand, HashCode );
    }
}

/*
This example of String.GetHashCode( ) generates the following output.

The hash code for "" is: 0x00001505, 5381
The hash code for "a" is: 0x0002B5C4, 177604
The hash code for "ab" is: 0x00596E26, 5860902
The hash code for "abc" is: 0x0B873285, 193409669
The hash code for "abd" is: 0x0B873282, 193409666
The hash code for "abe" is: 0x0B873283, 193409667
The hash code for "abcdef" is: 0x4DDB4BE2, 1306217442
The hash code for "abcdeg" is: 0x4DDB4BE3, 1306217443
The hash code for "abcdeh" is: 0x4DDB4BEC, 1306217452
The hash code for "abcdei" is: 0x4DDB4BED, 1306217453
The hash code for "Abcdeg" is: 0x941C4FC3, -1810083901
The hash code for "Abcdeh" is: 0x941C4FCC, -1810083892
The hash code for "Abcdei" is: 0x941C4FCD, -1810083891
*/
// Example for the String::GetHashCode( ) method.
using namespace System;
void DisplayHashCode( String^ Operand )
{
   int HashCode = Operand->GetHashCode();
   Console::WriteLine( "The hash code for \"{0}\"
 is: 0x{1:X8}, {1}", Operand, HashCode );
}

int main()
{
   Console::WriteLine( "This example of String::GetHashCode( ) "
   "generates the following output.\n" );
   DisplayHashCode( "" );
   DisplayHashCode( "a" );
   DisplayHashCode( "ab" );
   DisplayHashCode( "abc" );
   DisplayHashCode( "abd" );
   DisplayHashCode( "abe" );
   DisplayHashCode( "abcdef" );
   DisplayHashCode( "abcdeg" );
   DisplayHashCode( "abcdeh" );
   DisplayHashCode( "abcdei" );
   DisplayHashCode( "Abcdeg" );
   DisplayHashCode( "Abcdeh" );
   DisplayHashCode( "Abcdei" );
}

/*
This example of String::GetHashCode( ) generates the following output.

The hash code for "" is: 0x00001505, 5381
The hash code for "a" is: 0x0002B5C4, 177604
The hash code for "ab" is: 0x00596E26, 5860902
The hash code for "abc" is: 0x0B873285, 193409669
The hash code for "abd" is: 0x0B873282, 193409666
The hash code for "abe" is: 0x0B873283, 193409667
The hash code for "abcdef" is: 0x4DDB4BE2, 1306217442
The hash code for "abcdeg" is: 0x4DDB4BE3, 1306217443
The hash code for "abcdeh" is: 0x4DDB4BEC, 1306217452
The hash code for "abcdei" is: 0x4DDB4BED, 1306217453
The hash code for "Abcdeg" is: 0x941C4FC3, -1810083901
The hash code for "Abcdeh" is: 0x941C4FCC, -1810083892
The hash code for "Abcdei" is: 0x941C4FCD, -1810083891
*/
// Example for the String.GetHashCode( ) method.
import System.*;

class GetHashCode
{
    public static void main(String[]
 args)
    {
        Console.WriteLine(("This example of String.GetHashCode( ) " 
            + "generates the following output.\n"));
        DisplayHashCode("");
        DisplayHashCode("a");
        DisplayHashCode("ab");
        DisplayHashCode("abc");
        DisplayHashCode("abd");
        DisplayHashCode("abe");
        DisplayHashCode("abcdef");
        DisplayHashCode("abcdeg");
        DisplayHashCode("abcdeh");
        DisplayHashCode("abcdei");
        DisplayHashCode("Abcdeg");
        DisplayHashCode("Abcdeh");
        DisplayHashCode("Abcdei");
    } //main

    static void DisplayHashCode(String operand)
    {
        int hashCode = operand.GetHashCode();
        Console.WriteLine("The hash code for \"{0}\"
 is: 0x{1}, {2}", 
            operand, ((System.Int32)hashCode).ToString("X8"), 
            ((System.Int32)hashCode).ToString(""));
    } //DisplayHashCode
} //GetHashCode

/*
This example of String.GetHashCode( ) generates the following output.

The hash code for "" is: 0x00001505, 5381
The hash code for "a" is: 0x0002B5C4, 177604
The hash code for "ab" is: 0x00596E26, 5860902
The hash code for "abc" is: 0x0B873285, 193409669
The hash code for "abd" is: 0x0B873282, 193409666
The hash code for "abe" is: 0x0B873283, 193409667
The hash code for "abcdef" is: 0x4DDB4BE2, 1306217442
The hash code for "abcdeg" is: 0x4DDB4BE3, 1306217443
The hash code for "abcdeh" is: 0x4DDB4BEC, 1306217452
The hash code for "abcdei" is: 0x4DDB4BED, 1306217453
The hash code for "Abcdeg" is: 0x941C4FC3, -1810083901
The hash code for "Abcdeh" is: 0x941C4FCC, -1810083892
The hash code for "Abcdei" is: 0x941C4FCD, -1810083891
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS