Export (0) Print
Expand All

UTF8Encoding.GetHashCode Method

Returns the hash code for the current instance.

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)

public override int GetHashCode ()
public int GetHashCode ()
public override function GetHashCode () : int

Return Value

The hash code for the current instance.

The following example demonstrates how to use the GetHashCode method to return a hash code for an instance of UTF8Encoding. Notice that the hash code returned by this method varies depending on the constructor used to create the UTF8Encoding.

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());
    }
}

import System.*;
import System.Text.*;

class UTF8EncodingExample
{
    public static void main(String[] args)
    {
        // Many ways to instantiate a UTF8 encoding.
        UTF8Encoding utf8A = new UTF8Encoding();
        Encoding utf8B = Encoding.get_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());
    } //main
} //UTF8EncodingExample

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft