UTF8Encoding.GetHashCode Method

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 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 Example
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
      // 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.
      outputBlock.Text += UTF8a.GetHashCode() + "\n";
      outputBlock.Text += UTF8b.GetHashCode() + "\n";
      outputBlock.Text += UTF8c.GetHashCode() + "\n";
      outputBlock.Text += UTF8d.GetHashCode() + "\n";


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions