C# | CharEnumerator.GetHashCode() Method

GetHashCode() Method serves as the default hash function and returns a hash code for the current object. This method is inherited from the Object class.

Syntax:

public virtual int GetHashCode ();

Return Value: This method returns an Int32 value corresponding to the hash code of the current object.



Below are the programs to illustrate the use of CharEnumerator.GetHashCode() Method:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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());
    }
}

chevron_right


Output:

-381312627
1646495825

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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());
    }
}

chevron_right


Output:

491910500
-1775248344


My Personal Notes arrow_drop_up

Coder Machine Learner Social Activist Vocalist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.