Getting the hash code of the ValueTuple in C#
ValueTuple.GetHashCode Method is used to get the HashCode of the current ValueTuple instance. It is provided by the ValueTuple struct.
Syntax:
public override int GetHashCode ();
Returns: The return type of this method is System.Int32 and it always returns zero.
Example:
// C# program to illustrate how to // find the hash code of the given // value tuples. using System; class GFG { // Main method static public void Main() { // Creating a value tuple with zero element var MyTple1 = ValueTuple.Create(); Console.WriteLine("HashCode of a value tuple with"+ " zero elements: " + MyTple1.GetHashCode()); // Creating a value tuple with one element var MyTple2 = (23); Console.WriteLine("HashCode of a value tuple "+ "with one element: " + MyTple2.GetHashCode()); // Creating a value tuple with two elements var MyTple3 = (56, 45); Console.WriteLine("HashCode of a value tuple "+ "with two elements: " + MyTple3.GetHashCode()); // Creating a value tuple with three elements var MyTple4 = (67, 78, 89); Console.WriteLine("HashCode of a value tuple with "+ "three elements: " + MyTple4.GetHashCode()); // Creating a value tuple with four elements var MyTple5 = (09, 23, 12, 1); Console.WriteLine("HashCode of a value tuple with "+ "four elements: " + MyTple5.GetHashCode()); // Creating a value tuple with five elements var MyTple6 = (65, 87, 98, 23, 45); Console.WriteLine("HashCode of a value tuple with"+ " five elements: " + MyTple6.GetHashCode()); // Creating a value tuple with six elements var MyTple7 = (13, 56, 78, 12, 65, 98); Console.WriteLine("HashCode of a value tuple with"+ " six elements: " + MyTple7.GetHashCode()); // Creating a value tuple with seven elements var MyTple8 = (32, 45, 96, 78, 35, 33, 44); Console.WriteLine("HashCode of a value tuple with"+ " seven elements: " + MyTple8.GetHashCode()); } } |
chevron_right
filter_none
Output:
HashCode of a value tuple with zero elements: 0 HashCode of a value tuple with one element: 23 HashCode of a value tuple with two elements: -818407567 HashCode of a value tuple with three elements: -1237760639 HashCode of a value tuple with four elements: 2105592814 HashCode of a value tuple with five elements: 695326364 HashCode of a value tuple with six elements: -335480823 HashCode of a value tuple with seven elements: -2111090807
Recommended Posts:
- Getting the Hash Code of the Specified Range in C#
- C# | How to get hash code for the specified key of a Hashtable
- Getting the Hash Code of the Given Index in C#
- ValueTuple in C#
- How to create 1-ValueTuple in C#?
- ValueTuple Struct in C#
- C# | ValueTuple <T1,T2,T3,T4,T5,T6,T7> Struct
- How to get Second Element of the ValueTuple in C#?
- How to get fifth Element of the ValueTuple in C#?
- How to get First Element of the ValueTuple in C#?
- C# | ValueTuple <T1,T2> Struct
- C# | ValueTuple <T1,T2,T3,T4,T5,T6> Struct
- How to get third Element of the ValueTuple in C#?
- How to create 2-ValueTuple in C#?
- How to create 4-ValueTuple in C#?
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.


