A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/c-sharp/c-sharp-char-gethashcode-method-with-examples/ below:

C# | Char.GetHashCode() Method with Examples

C# | Char.GetHashCode() Method with Examples

Last Updated : 11 Jul, 2025

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: 

csharp
// C# program to demonstrate
// Char.GetHashCode() Method
using System;

class GFG {

    // Main Method
    public static void Main()
    {

        // declaring and initializing char
        char ch1 = 'B';

        // checking condition
        // using GetHashCode() Method
        int val = ch1.GetHashCode();

        // Display Hashcode
        Console.WriteLine("Hashcode :- {0}", val);
    }
}
Output:
Hashcode :- 4325442

Example 2: 

csharp
// 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 GetHashCode() Method
        int val = ch.GetHashCode();

        // Display Hashcode
        Console.WriteLine("Hashcode of " + ch +
                                " :- {0}", val);
    }
}
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:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4