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:
// 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()); } } |
Output:
-381312627 1646495825
Example 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()); } } |
Output:
491910500 -1775248344
Please Login to comment...