Open In App

UInt16.GetHashCode Method in C# with Examples

Last Updated : 01 May, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
UInt16.GetHashCode method is used to get the HashCode for the current UInt16 instance.
Syntax: public override int GetHashCode (); Return Value: This method returns a 32-bit signed integer hash code.
Below programs illustrate the use of the above discussed-method: Example 1: csharp
// C# program to illustrate the
// UInt16.GetHashCode() Method
using System;

class GFG {

    // Main Method
    public static void Main()
    {

        // Taking UInt16 variable
        // i.e. ushort data type
        ushort s1 = 124;

        // Getting the hash code for UInt16
        // using GetHashCode() method
        int result = s1.GetHashCode();

        // Display the HashCode
        Console.WriteLine("HashCode for UInt16 is: {0}",
                                                result);
    }
}
Output:
HashCode for UInt16 is: 124
Example 2: csharp
// C# program to illustrate the
// UInt16.GetHashCode() Method
using System;

class GFG {

    // Main Method
    public static void Main()
    {
        // using result() Method
        result(UInt16.MinValue);
        result(UInt16.MaxValue);
    }

    // result() method
    public static void result(ushort val)
    {

        // using GetHashCode() method
        int code = val.GetHashCode();

        // Display the hashcode
        Console.WriteLine("HashCode for {0} is {1}",
                                         val, code);
    }
}
Output:
HashCode for 0 is 0
HashCode for 65535 is 65535
Reference:

Next Article

Similar Reads