This documentation is archived and is not being maintained.

UnicodeEncoding.GetHashCode Method

Returns the hash code for this instance.

[Visual Basic]
Overrides Public Function GetHashCode() As Integer
[C#]
public override int GetHashCode();
[C++]
public: int GetHashCode();
[JScript]
public override function GetHashCode() : int;

Return Value

A 32-bit signed integer hash code.

Example

[Visual Basic, C#, C++] The following example demonstrates how to use the GetHashCode method to return a hashcode for an instance of a UnicodeEncoding. Notice that regardless of how a UnicodeEncoding is created, all instances return the same hash code.

[Visual Basic] 
Imports System
Imports System.Text

Class UnicodeEncodingExample
    
    Public Shared Sub Main()
        Dim unicode1 As New UnicodeEncoding()
        Dim unicode2 As Encoding = Encoding.Unicode
        
        Console.WriteLine(unicode1.GetHashCode())
        Console.WriteLine(unicode2.GetHashCode())
    End Sub 'Main 
End Class 'UnicodeEncodingExample

[C#] 
using System;
using System.Text;

class UnicodeEncodingExample {
    public static void Main() {
        UnicodeEncoding unicode1 = new UnicodeEncoding();
        Encoding unicode2 = Encoding.Unicode;

        Console.WriteLine(unicode1.GetHashCode());
        Console.WriteLine(unicode2.GetHashCode());

    }
}

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Text;

int main()
{
   UnicodeEncoding* unicode1 = new UnicodeEncoding();
   Encoding * unicode2 = Encoding::Unicode;

   Console::WriteLine(unicode1 -> GetHashCode());
   Console::WriteLine(unicode2 -> GetHashCode());
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

UnicodeEncoding Class | UnicodeEncoding Members | System.Text Namespace

Show: