UTF8Encoding.GetHashCode Method
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Returns the hash code for the current instance.
Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Overrides Function GetHashCode As Integer
public override int GetHashCode()
Return Value
Type: System.Int32
The hash code for the current instance.
Examples
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.
Imports System.Text
Class Example
Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
' 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.
outputBlock.Text &= UTF8a.GetHashCode() & vbCrLf
outputBlock.Text &= UTF8b.GetHashCode() & vbCrLf
outputBlock.Text &= UTF8c.GetHashCode() & vbCrLf
outputBlock.Text &= UTF8d.GetHashCode() & vbCrLf
End Sub 'Main
End Class 'UTF8EncodingExample
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";
}
}
Version Information
Silverlight
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
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.