C#のUri.GetHashCode()メソッド
C#のUri.GetHashCode()メソッドは、URIのハッシュコードを取得します。
構文
以下は構文です-
public override int GetHashCode ();
例
Uri.GetHashCode()メソッドを実装する例を見てみましょう-
using System; public class Demo { public static void Main(){ string URI1 = "https://www.tutorialspoint.com/index.htm"; Console.WriteLine("URI = "+URI1); string URI2 = "https://www.tutorialspoint.com/"; Console.WriteLine("URI = "+URI2); Console.WriteLine("Escaped string (URI1) = "+Uri.EscapeDataString(URI1)); Console.WriteLine("Escaped string (URI2) = "+Uri.EscapeDataString(URI2)); Console.WriteLine("GetHashCode() for URI1 = "+URI1.GetHashCode()); Console.WriteLine("GetHashCode() for URI2 = "+URI2.GetHashCode()); } }
出力
これにより、次の出力が生成されます-
URI = https://www.tutorialspoint.com/index.htm URI = https://www.tutorialspoint.com/ Escaped string (URI1) = https%3A%2F%2Fwww.tutorialspoint.com%2Findex.htm Escaped string (URI2) = https%3A%2F%2Fwww.tutorialspoint.com%2F GetHashCode() for URI1 = -799747664 GetHashCode() for URI2 = 211597894
例
Uri.GetHashCode()メソッドを実装する別の例を見てみましょう-
using System; public class Demo { public static void Main(){ string URI1 = "https://www.qries.com/index.htm"; Console.WriteLine("URI = "+URI1); string URI2 = "https://www.qries.com/"; Console.WriteLine("URI = "+URI2); Console.WriteLine("Escaped string (URI1) = "+Uri.EscapeDataString(URI1)); Console.WriteLine("Escaped string (URI2) = "+Uri.EscapeDataString(URI2)); Console.WriteLine("GetHashCode() for URI1 = "+URI1.GetHashCode()); Console.WriteLine("GetHashCode() for URI2 = "+URI2.GetHashCode()); } }
出力
これにより、次の出力が生成されます-
URI = https://www.qries.com/index.htm URI = https://www.qries.com/ Escaped string (URI1) = https%3A%2F%2Fwww.qries.com%2Findex.htm Escaped string (URI2) = https%3A%2F%2Fwww.qries.com%2F GetHashCode() for URI1 = -39330946 GetHashCode() for URI2 = -262746624
-
C#のType.GetHashCode()メソッド
C#のType.GetHashCode()メソッドは、このインスタンスのハッシュコードを返すために使用されます。 構文 以下は構文です- public override int GetHashCode (); 例 Type.GetHashCode()メソッドを実装する例を見てみましょう- using System; public class Demo { public static void Main(){ string[] arr = {"tom", "amit", "k
-
C#のCharEnumerator.GetHashCode()メソッド
C#のCharEnumerator.GetHashCode()メソッドは、現在のオブジェクトのハッシュコードを返します。 構文 public virtual int GetHashCode (); ここで、CharEnumerator.GetHashCode()メソッドを実装する例を見てみましょう- 例 using System; public class Demo { public static void Main(){ string strNum = "john"; &nb