UTF8Encoding.GetHashCode Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns the hash code for the current instance.
public:
override int GetHashCode();
public override int GetHashCode ();
override this.GetHashCode : unit -> int
Public Overrides Function GetHashCode () As Integer
Returns
The hash code for the current instance.
Examples
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 namespace System;
using namespace System::Text;
int main()
{
// Many ways to instantiate a UTF8 encoding.
UTF8Encoding^ UTF8a = gcnew UTF8Encoding;
Encoding^ UTF8b = Encoding::UTF8;
Encoding^ UTF8c = gcnew UTF8Encoding( true,true );
Encoding^ UTF8d = gcnew 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() );
}
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());
}
}
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
End Class
Applies to
See also
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET