UTF8Encoding.GetHashCode Method ()


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Returns the hash code for the current instance.

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

public override int GetHashCode()

Return Value

Type: System.Int32

The hash code for the current instance.

The following example uses the GetHashCode method to return a hash code for UTF8Encoding instances. Notice that the hash code returned by this method depends on the constructor used to create the UTF8Encoding object.

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.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top