UTF8Encoding.GetHashCode Methode

Definitie

Retourneert de hash-code voor het huidige exemplaar.

public:
 override int GetHashCode();
public override int GetHashCode();
override this.GetHashCode : unit -> int
Public Overrides Function GetHashCode () As Integer

Retouren

De hash-code voor het huidige exemplaar.

Voorbeelden

In het volgende voorbeeld wordt de GetHashCode methode gebruikt om een hash-code voor UTF8Encoding exemplaren te retourneren. U ziet dat de hashcode die door deze methode wordt geretourneerd, afhankelijk is van de constructor die wordt gebruikt om het UTF8Encoding object te maken.

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

Van toepassing op

Zie ook