Share via


IdnMapping.GetHashCode Método

Definición

Devuelve un código hash para este objeto IdnMapping.

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

Devoluciones

Una de las cuatro constantes con signo de 32 bits derivadas de las propiedades de un objeto IdnMapping. El valor devuelto no tiene un significado especial y no es apropiado para utilizarlo en un algoritmo de código hash.

Ejemplos

En el ejemplo siguiente se supone que una sola cadena puede contener varias direcciones de correo electrónico separadas por espacios. Quita la parte local y el carácter @ de cada dirección de correo electrónico y pasa el nombre de dominio resultante al GetAscii(String, Int32) método o GetAscii(String, Int32, Int32) para crear un nombre de dominio punycode. A GetUnicode(String, Int32, Int32) continuación, el método convierte el nombre de dominio punycode en el nombre de dominio original.

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 --> мойдомен.рф

Comentarios

Invalide el método si la GetHashCode aplicación necesita implementar un algoritmo de código hash significativo.

Se aplica a