IdnMapping.GetHashCode Method

Returns a hash code for this IdnMapping object.

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)

public override int GetHashCode()

Return Value

Type: System.Int32
One of four 32-bit signed constants derived from the properties of an IdnMapping object. The return value has no special meaning and is not suitable for use in a hash code algorithm.

Override the GetHashCode method if your application needs to implement a meaningful hash code algorithm.

The following example assumes that a single string can contain multiple email addresses separated by spaces. It removes the local part and the @ character from each email address, and passes the resulting domain name to the GetAscii(String, Int32) or GetAscii(String, Int32, Int32) method to create a Punycode domain name. The GetUnicode(String, Int32, Int32) method then converts the Punycode domain name back into the original domain name.

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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft