Open In App

UInt16.GetHashCode Method in C# with Examples

Last Updated : 01 May, 2019
Improve
Improve
Like Article
Like
Save
Share
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:




// 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:




// 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:



Similar Reads

UInt16.GetTypeCode Method in C# with Examples
UInt16.GetTypeCode method is used to get the TypeCode for value type UInt16. Syntax: public TypeCode GetTypeCode (); Return Value: This method returns the enumerated constant UInt16. Below programs illustrate the use of the above discussed-method: Example 1: // C# program to illustrate the // UInt16.GetTypeCode() Method using System; class GFG { //
1 min read
UInt16.CompareTo() Method in C# with Examples
UInt16.CompareTo Method is used to compare the current instance to a specified object or another UInt16 instance. It returns an integer which shows whether the value of the current instance is less than, equal to, or greater than the value of the specified object or the other UInt16 instance. There are 2 methods in the overload list of this method
4 min read
UInt16.Equals Method in C# with Examples
UInt16.Equals Method is used to get a value which indicates whether the current instance is equal to a specified object or 16-bit unsigned integer or not. There are 2 methods in the overload list of this method as follows: Equals(UInt16) Method Equals(Object) Method UInt16.Equals(UInt16) Method This method is used to return a value indicating wheth
3 min read
UInt16.ToString() Method in C# with Examples | Set - 1
UInt16.ToString Method is used to convert the numeric value of the current UInt16 instance to its equivalent string representation. There are 4 methods in the overload list of this method as follows: ToString(IFormatProvider) Method ToString(String, IFormatProvider) Method ToString() Method ToString(String) Method Here, we will discuss the first tw
3 min read
UInt16.ToString Method in C# with Examples | Set - 2
UInt16.ToString Method is used to convert the numeric value of the current instance to its equivalent string representation. There are 4 methods in the overload list of this method as follows: ToString(IFormatProvider) Method ToString(String, IFormatProvider) Method ToString() Method ToString(String) Method Here, we will discuss the last two method
2 min read
UInt16.Parse(String) Method in C# with Examples
UInt16.Parse(String) Method is used to convert the string representation of a number to its 16-bit unsigned integer equivalent. Syntax: public static ushort Parse (string str); Here, str is a string containing a number to convert. The format of str will be [optional white space][optional sign]digits[optional white space]. The sign can be positive o
2 min read
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/C++ Code // C# program to demonstrate // Char.GetHashCode() Method using System; class GFG { // M
1 min read
C# | Object.GetHashCode() Method with Examples
This method is used to return the hash code for this instance. A hash code is a numeric value which is used to insert and identify an object in a hash-based collection. The GetHashCode method provides this hash code for algorithms that need quick checks of object equality. Syntax: public virtual int GetHashCode (); Return Value: This method returns
2 min read
Decimal.GetHashCode Method in C# with Examples
Decimal.GetHashCode method is used to get the HashCode for the current Decimal 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: // C# program to illustrate the // Decimal.GetHashCode() Method using Sy
1 min read
Int16.GetHashCode Method in C# with Examples
Int16.GetHashCode method is used to get the HashCode for the current Int16 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: // C# program to illustrate the // Int16.GetHashCode() Method using System;
1 min read