C# | How to get the HashCode of the tuple?
A tuple is a data structure which gives you the easiest way to represent a data set. You can also get the hash code of the tuple by using the GetHashCode Method. This method will return the hash code of the given tuple object.
Syntax:
public override int GetHashCode ();
Return Type: The return type of this method is System.Int32. It will return 32-bit signed integer hash code.
Example 1:
// C# program to illustrate the // use of GetHashCode method using System; class GFG { // Main Method static public void Main() { // creating different tuples using Create Method var tu1 = Tuple.Create(23, 45, 78, 89, 56); var tu2 = Tuple.Create(34, 45); var tu3 = Tuple.Create(45, 454, 454, 545, 4, 544, 54, 56); var tu4 = Tuple.Create(44, 58, 66, 32); // Get the hash code of the Tuples // Using GetHashCode method Console.WriteLine("HashCode for tu1: " + tu1.GetHashCode()); Console.WriteLine("HashCode for tu2: " + tu2.GetHashCode()); Console.WriteLine("HashCode for tu3: " + tu3.GetHashCode()); Console.WriteLine("HashCode for tu4: " + tu4.GetHashCode()); } } |
chevron_right
filter_none
Output:
HashCode for tu1: 712149 HashCode for tu2: 1103 HashCode for tu3: 1582758 HashCode for tu4: 45300
Example 2:
// C# program to illustrate the use // of the GetHashCode method using System; class GFG { // Main Method static public void Main() { // Creating different Tuples // using Create Method var t1 = Tuple.Create(64, 76, 78, Tuple.Create(12, 34, 56, 78)); var t2 = Tuple.Create(78, 34, 86, Tuple.Create(23, 56)); var t3 = Tuple.Create(34, 78, Tuple.Create(12, 34, 56, 78)); var t4 = Tuple.Create(12, 34, 56, 34, 56, 65, 78, Tuple.Create(24, 45, 67, 78, 89, 88)); // Get the hash code of the Tuples // Using GetHashCode method Console.WriteLine("HashCode for t1: " + t1.GetHashCode()); Console.WriteLine("HashCode for t2: " + t2.GetHashCode()); Console.WriteLine("HashCode for t3: " + t3.GetHashCode()); Console.WriteLine("HashCode for t4: " + t4.GetHashCode()); } } |
chevron_right
filter_none
Output:
HashCode for t1: 78746 HashCode for t2: 83573 HashCode for t3: 47540 HashCode for t4: 672122
Recommended Posts:
- How to create 2-tuple or pair tuple in C#?
- How to create 1-Tuple or Singleton Tuple in C#?
- How to create 3-Tuple or Triple Tuple in C#?
- C# | Tuple
- C# | How to get the HashCode for the string
- How to get the hashcode for enum in C#?
- C# | Tuple<T1,T2,T3,T4> Class
- C# | Tuple<T1,T2,T3> Class
- C# | Tuple<T1,T2,T3,T4,T5> Class
- C# | Tuple<T1,T2,T3,T4,T5,T6> Class
- C# | Tuple<T1,T2,T3,T4,T5,T6,T7> Class
- How to create 6-Tuple in C#?
- C# | Tuple<T1> Class
- C# | Tuple<T1,T2> Class
- C# | How to get Third Element of the Tuple?
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.



