Boolean.GetHashCode() Method in C# with Examples

Boolean.GetHashCode() 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 Boolean.GetHashCode() Method:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the
// Boolean.GetHashCode() Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
  
        // Declaring and initializing value1
        bool value1 = true;
  
        // getting the HashCode
        // using GetHashCode() method
        int value = value1.GetHashCode();
  
        // Display the HashCode
        Console.WriteLine("HashCode is {0}", value);
    }
}

chevron_right


Output:

HashCode is 1

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the
// Boolean.GetHashCode() Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // calling get() method
        get(true);
        get(false);
    }
  
    // defining get() method
    public static void get(bool value1)
    {
  
        // getting the HashCode
        // using GetHashCode() method
        int value = value1.GetHashCode();
  
        // Display the HashCode
        Console.WriteLine("HashCode is {0}", value);
    }
}

chevron_right


Output:

HashCode is 1
HashCode is 0

Reference:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.