C# | Char.GetHashCode() Method with Examples
This method is used to return the hash code for this instance.
Syntax:
public override int GetHashCode ();
Return Value: This method returns a 32-bit signed integer hash code.
Below programs illustrate the use of Char.GetHashCode() Method:
Example 1:
// C# program to demonstrate // Char.GetHashCode() Method using System; class GFG { // Main Method public static void Main() { // declaring and intializing char char ch1 = 'B'; // checking condition // using Equals() Method int val = ch1.GetHashCode(); // Display Hashcode Console.WriteLine("Hashcode :- {0}", val); } } |
chevron_right
filter_none
Output:
Hashcode :- 4325442
Example 2:
// C# program to demonstrate // Char.GetHashCode() Method using System; class GFG { // Main Method public static void Main() { // calling hash() Method hash('a'); hash('b'); hash('c'); hash('x'); hash('y'); hash('z'); } // Defining hash() Method public static void hash(char ch) { // checking condition // using Equals() Method int val = ch.GetHashCode(); // Display Hashcode Console.WriteLine("Hashcode of " + ch + " :- {0}", val); } } |
chevron_right
filter_none
Output:
Hashcode of a :- 6357089 Hashcode of b :- 6422626 Hashcode of c :- 6488163 Hashcode of x :- 7864440 Hashcode of y :- 7929977 Hashcode of z :- 7995514
Reference:
Recommended Posts:
- MathF.Log() Method in C# with Examples
- MathF.Exp() Method in C# with Examples
- MathF.Cos() Method in C# with Examples
- MathF.Tan() Method in C# with Examples
- MathF.Min() Method in C# with Examples
- MathF.Max() Method in C# with Examples
- MathF.Sin() Method in C# with Examples
- MathF.Abs() Method in C# with Examples
- MathF.Pow() Method in C# with Examples
- UInt16.ToString() Method in C# with Examples | Set - 1
- UInt32.Equals Method in C# with Examples
- MathF.Acos() Method in C# with Examples
- Single.Equals() Method in C# with Examples
- Single.GetTypeCode Method in C# with Examples
- UInt64.Equals Method in C# with Examples
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.



