IdnMapping.GetHashCode Metodo

Definizione

Restituisce un codice hash per l'oggetto IdnMapping.

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

Restituisce

Una delle quattro costanti con segno a 32 bit derivate dalle proprietà di un oggetto IdnMapping. Il valore restituito non ha alcun significato speciale e non può essere utilizzato in un algoritmo di codice hash.

Esempio

Nell'esempio seguente si presuppone che una singola stringa possa contenere più indirizzi di posta elettronica separati da spazi. Rimuove la parte locale e il carattere @ da ogni indirizzo di posta elettronica e passa il nome di dominio risultante al GetAscii(String, Int32) metodo o GetAscii(String, Int32, Int32) per creare un nome di dominio Punycode. Il GetUnicode(String, Int32, Int32) metodo converte quindi il nome di dominio Punycode nel nome di dominio originale.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      string email = "johann_doe@bücher.com john_doe@hotmail.com иван@мойдомен.рф";
      IdnMapping idn = new IdnMapping();
      int start = 0, end = 0;

      while (end >= 0) {
         start = email.IndexOf("@", end);
         end = email.IndexOf(" ", start);
         string domain = String.Empty;

         try {
            string punyCode = String.Empty;
            if (start >= 0 && end >= 0) {
               domain = email.Substring(start + 1, end - start - 1);
               punyCode = idn.GetAscii(email, start + 1, end - start - 1);
            }
            else {
               domain = email.Substring(start + 1);
               punyCode = idn.GetAscii(email, start + 1);
            }
            string name2 = idn.GetUnicode(punyCode);
            Console.WriteLine("{0} --> {1} --> {2}", domain, punyCode, name2);
         }
         catch (ArgumentException) {
            Console.WriteLine("{0} is not a valid domain name.", domain);
         }
         Console.WriteLine();
      }
   }
}
// The example displays the following output:
//       bücher.com --> xn--bcher-kva.com --> bücher.com
//
//       hotmail.com --> hotmail.com --> hotmail.com
//
//       мойдомен.рф --> xn--d1acklchcc.xn--p1ai --> мойдомен.рф
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim email As String = "johann_doe@bücher.com john_doe@hotmail.com иван@мойдомен.рф"
      Dim idn As New IdnMapping()
      Dim start, [end] As Integer
      
      Do While [end] >= 0
         start = email.IndexOf("@", [end])
         [end] = email.IndexOf(" ", start)
         Dim domain As String = String.Empty
         
         Try
            Dim punyCode As String = String.Empty
            If start >= 0 And [end] >= 0 Then 
               domain = email.Substring(start + 1, [end] - start - 1)
               punyCode = idn.GetAscii(email, start + 1, [end] - start - 1)
            Else
               domain = email.Substring(start + 1)
               punyCode = idn.GetAscii(email, start + 1)
            End If
            Dim name2 As String = idn.GetUnicode(punyCode)
            Console.WriteLine("{0} --> {1} --> {2}", domain, punyCode, name2) 
         Catch e As ArgumentException 
            Console.WriteLine("{0} is not a valid domain name.", domain)
         End Try
         Console.WriteLine()
      Loop   
   End Sub
End Module
' The example displays the following output:
'       bücher.com --> xn--bcher-kva.com --> bücher.com
'       
'       hotmail.com --> hotmail.com --> hotmail.com
'       
'       мойдомен.рф --> xn--d1acklchcc.xn--p1ai --> мойдомен.рф

Commenti

Eseguire l'override del metodo se l'applicazione GetHashCode deve implementare un algoritmo di codice hash significativo.

Si applica a