GetHashCode()方法用作默認的哈希函數,並返回當前對象的哈希碼。此方法從Object類繼承。
用法:
public virtual int GetHashCode ();
返回值:此方法返回一個與當前對象的哈希碼相對應的Int32值。
以下示例程序旨在說明CharEnumerator.GetHashCode()方法的使用:
示例1:
// C# program to illustrate the use
// of CharEnumerator.GetHashCode()
// Method
using System;
class GFG {
// Driver code
public static void Main()
{
// Initialize a string object
string str = "GeeksforGeeks is fun";
// Instantiate a CharEnumerator object
CharEnumerator chEnum1 = str.GetEnumerator();
// Instantiate another CharEnumerator object
CharEnumerator chEnum2 = str.GetEnumerator();
// Printing the Hash Code of
// both the CharEnumerator objects
Console.WriteLine(chEnum1.GetHashCode());
Console.WriteLine(chEnum2.GetHashCode());
}
}
輸出:
-381312627 1646495825
示例2:
// C# program to illustrate the use
// of CharEnumerator.GetHashCode()
// Method
using System;
class GFG {
// Driver code
public static void Main()
{
// Initialize two string object
string str1 = "GeeksforGeeks is fun",
str2 = "C C++ Java Python";
// Instantiate a CharEnumerator object
CharEnumerator chEnum1 = str1.GetEnumerator();
// Instantiate another CharEnumerator object
CharEnumerator chEnum2 = str2.GetEnumerator();
// Printing the Hash Code of
// both the CharEnumerator objects
Console.WriteLine(chEnum1.GetHashCode());
Console.WriteLine(chEnum2.GetHashCode());
}
}
輸出:
491910500 -1775248344
相關用法
- C# DateTimeOffset.Add()用法及代碼示例
- C# String.Contains()用法及代碼示例
- C# Math.Sin()用法及代碼示例
- C# Math.Cos()用法及代碼示例
- C# Dictionary.Add()用法及代碼示例
- C# Math.Tan()用法及代碼示例
- C# Math.Abs()方法用法及代碼示例
- C# Math.Exp()用法及代碼示例
- C# Math.Abs()函數用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 C# | CharEnumerator.GetHashCode() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。