📜  C#| CharEnumerator.GetHashCode()方法

📅  最后修改于: 2021-05-29 20:16:39             🧑  作者: Mango

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