C# | CharEnumerator.GetHashCode() Method
Last Updated :
30 Apr, 2019
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:
using System;
class GFG {
public static void Main()
{
string str = "GeeksforGeeks is fun" ;
CharEnumerator chEnum1 = str.GetEnumerator();
CharEnumerator chEnum2 = str.GetEnumerator();
Console.WriteLine(chEnum1.GetHashCode());
Console.WriteLine(chEnum2.GetHashCode());
}
}
|
Output:
-381312627
1646495825
Example 2:
using System;
class GFG {
public static void Main()
{
string str1 = "GeeksforGeeks is fun" ,
str2 = "C C++ Java Python" ;
CharEnumerator chEnum1 = str1.GetEnumerator();
CharEnumerator chEnum2 = str2.GetEnumerator();
Console.WriteLine(chEnum1.GetHashCode());
Console.WriteLine(chEnum2.GetHashCode());
}
}
|
Output:
491910500
-1775248344
Share your thoughts in the comments
Please Login to comment...