IdnMapping.GetHashCode 메서드

정의

IdnMapping 개체의 해시 코드를 반환합니다.

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

반환

IdnMapping 개체의 속성에서 파생된 네 개의 부호 있는 32비트 상수 중 하나입니다. 반환 값에는 특별한 의미가 없으므로 해시 코드 알고리즘에 사용하기는 적합하지 않습니다.

예제

다음 예제에서는 단일 문자열에 공백으로 구분된 여러 전자 메일 주소를 포함할 수 있다고 가정합니다. 각 전자 메일 주소에서 로컬 부분과 @ 문자를 제거하고 결과 도메인 이름을 또는 GetAscii(String, Int32, Int32) 메서드에 GetAscii(String, Int32) 전달하여 Punycode 도메인 이름을 만듭니다. 그런 다음, 메서드는 GetUnicode(String, Int32, Int32) Punycode 도메인 이름을 원래 도메인 이름으로 다시 변환합니다.

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

설명

재정의 GetHashCode 메서드 애플리케이션에서 의미 있는 해시 코드 알고리즘을 구현 해야 합니다.

적용 대상