Export (0) Print
Expand All

UTF8Encoding.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 UTF8Encoding. Notice that the hashcode returned by this method varies depending on the constructor used to create the UTF8Encoding.

[Visual Basic] 
Imports System
Imports System.Text

Class UTF8EncodingExample
    
    Public Shared Sub Main()
        ' Many ways to instantiate a UTF8 encoding.
        Dim UTF8a As New UTF8Encoding()
        Dim UTF8b As Encoding = Encoding.UTF8
        Dim UTF8c = New UTF8Encoding(True, True)
        Dim UTF8d = New UTF8Encoding(False, False)
        
        ' But not all are the same.
        Console.WriteLine(UTF8a.GetHashCode())
        Console.WriteLine(UTF8b.GetHashCode())
        Console.WriteLine(UTF8c.GetHashCode())
        Console.WriteLine(UTF8d.GetHashCode())
    End Sub 'Main
End Class 'UTF8EncodingExample

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

class UTF8EncodingExample {
    public static void Main() {
        // Many ways to instantiate a UTF8 encoding.
        UTF8Encoding UTF8a = new UTF8Encoding();
        Encoding UTF8b = Encoding.UTF8;
        Encoding UTF8c = new UTF8Encoding(true, true);
        Encoding UTF8d = new UTF8Encoding(false, false);

        // But not all are the same.
        Console.WriteLine(UTF8a.GetHashCode());
        Console.WriteLine(UTF8b.GetHashCode());
        Console.WriteLine(UTF8c.GetHashCode());
        Console.WriteLine(UTF8d.GetHashCode());
    }
}

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

int main()
{
   // Many ways to instantiate a UTF8 encoding.
   UTF8Encoding* UTF8a = new UTF8Encoding();
   Encoding* UTF8b = Encoding::UTF8;
   Encoding* UTF8c = new UTF8Encoding(true, true);
   Encoding* UTF8d = new UTF8Encoding(false, false);

   // But not all are the same.
   Console::WriteLine(UTF8a -> GetHashCode());
   Console::WriteLine(UTF8b -> GetHashCode());
   Console::WriteLine(UTF8c -> GetHashCode());
   Console::WriteLine(UTF8d -> 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

UTF8Encoding Class | UTF8Encoding Members | System.Text Namespace

Show:
© 2015 Microsoft