Get the HashCode for the current UInt32 instance in C#


To get the HashCode for the current UInt32 instance, the code is as follows −

Example

 Live Demo

using System;
public class Demo {
   public static void Main() {
      uint val1 = 100;
      uint val2 = UInt16.MinValue;
      Console.WriteLine("HashCode for val1 = "+val1.GetHashCode());
      Console.WriteLine("HashCode for val2 = "+val2.GetHashCode());
   }
}

Output

This will produce the following output −

HashCode for val1 = 100
HashCode for val2 = 0

Example

Let us see another example −

 Live Demo

using System;
public class Demo {
   public static void Main() {
      uint val1 = 50;
      uint val2 = UInt16.MaxValue;
      Console.WriteLine("HashCode for val1 = "+val1.GetHashCode());
      Console.WriteLine("HashCode for val2 = "+val2.GetHashCode());
   }
}

Output

This will produce the following output −

HashCode for val1 = 50
HashCode for val2 = 65535

Updated on: 11-Dec-2019

65 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements