UTF8Encoding.GetHashCode 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回当前实例的哈希代码。
public:
override int GetHashCode();
public override int GetHashCode ();
override this.GetHashCode : unit -> int
Public Overrides Function GetHashCode () As Integer
返回
当前实例的哈希代码。
示例
以下示例使用 GetHashCode 方法返回 实例的 UTF8Encoding 哈希代码。 请注意,此方法返回的哈希代码取决于用于创建对象的 UTF8Encoding 构造函数。
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