IdnMapping.GetHashCode 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
이 IdnMapping 개체에 대한 해시 코드를 반환합니다.
public:
override int GetHashCode();
public override int GetHashCode();
override this.GetHashCode : unit -> int
Public Overrides Function GetHashCode () As Integer
반품
개체의 속성에서 파생된 32비트 부속 상수 4개 중 하나입니다 IdnMapping . 반환 값은 특별한 의미가 없으며 해시 코드 알고리즘에 사용하기에 적합하지 않습니다.
예제
다음 예제에서는 단일 문자열에 공백으로 구분된 여러 전자 메일 주소를 포함할 수 있다고 가정합니다. 각 전자 메일 주소에서 로컬 부분과 @ 문자를 제거하고 결과 도메인 이름을 또는 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 의미 있는 해시 코드 알고리즘을 구현해야 하는 경우 메서드를 재정의합니다.