当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C# CharEnumerator.GetHashCode()用法及代码示例


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


相关用法


注:本文由纯净天空筛选整理自rupesh_rao大神的英文原创作品 C# | CharEnumerator.GetHashCode() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。