Getting the Hash Code of the Given Index in C# Last Updated : 28 Nov, 2019 Comments Improve Suggest changes Like Article Like Report The Index Structure is introduced in C# 8.0. It represents a type that can be used to index a collection or sequence and it can be started from the start or the end. You are allowed to find the hash code of the specified index with the help of the GetHashCode Method provided by the Index struct. This method returns the hash code of the specified index. Syntax: public override int GetHashCode(); Example 1: CSharp // C# program to illustrate the // concept of the GetHashCode() method using System; namespace example { class GFG { // Main Method static void Main(string[] args) { // Creating new indexes // Using Index() constructor var in1 = new Index(1, true); var in2 = new Index(3, false); // Getting the hash code // of the given index // Using GetHashCode() method var res1 = in1.GetHashCode(); var res2 = in2.GetHashCode(); // Displaying the index Console.WriteLine("Hash Code of Index: {0} is: {1} ", in1, res1); Console.WriteLine("Hash Code of Index: {0} is: {1} ", in2, res2); } } } Output: Hash Code of Index: ^1 is: -2 Hash Code of Index: 3 is: 3 Example 2: CSharp // C# program to illustrate the concept // of the GetHashCode() method using System; namespace example { class GFG { // Main Method static void Main(string[] args) { // Creating and initializing an array string[] greetings = new string[] {"Hello", "Hola", "Namaste", "Bonjour", "Ohayo", "Ahnyounghaseyo"}; // Creating new indexes // Using Index() constructor var in1 = new Index(2, true); var in2 = new Index(3, false); var in3 = new Index(2, false); // Getting the hash code // of the given indexes // Using GetHashCode() method var res1 = greetings[in1].GetHashCode(); var res2 = greetings[in2].GetHashCode(); var res3 = greetings[in3].GetHashCode(); // Displaying the index Console.WriteLine("Index: {0} Value: {1} HashCode: {2} ", in1, greetings[in1], res1); Console.WriteLine("Index: {0} Value: {1} HashCode: {2} ", in2, greetings[in2], res2); Console.WriteLine("Index: {0} Value: {1} HashCode: {2} ", in3, greetings[in3], res3); } } } Output: Index: ^2 Value: Ohayo HashCode: -1302855152 Index: 3 Value: Bonjour HashCode: 399419679 Index: 2 Value: Namaste HashCode: 1350085290 Comment More infoAdvertise with us Next Article Getting the Hash Code of the Given Index in C# ankita_saini Follow Improve Article Tags : C# CSharp-8.0 Similar Reads 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: CSharp // C# program to illu 2 min read Getting the Hash Code of the Specified Range in C# The Range Structure is introduced in C# 8.0. It represents a range that has a start and end indexes. You are allowed to get the hash code of the specified range with the help of the GetHashCode() Method provided by the Range struct. This method returns the hash code of the specified instance. Syntax 2 min read Checking the Given Indexes are Equal or not in C# The Index Structure is introduced in C# 8.0. It represents a type that can be used to index a collection or sequence and it can be started from the start or the end. You are allowed to compare two indexes with each to check whether they are equal or not with the help of the following methods(Equal M 3 min read How to get the index value in C#? The Index Structure is introduced in C# 8.0. It represents a type that can be used to index a collection or sequence and it can be started from the start or the end. You are allowed to get the index value with the help of Value Property provided by the Index struct. Syntax: public int Value { int ge 2 min read C# | Gets an ICollection containing the keys in the Hashtable Hashtable.Keys Property is used to get an ICollection containing the keys in the Hashtable. Syntax: public virtual System.Collections.ICollection Keys { get; } Return Value: This property returns an ICollection containing the keys in the Hashtable. Note: The order of keys in the ICollection is unspe 2 min read C# | Gets an ICollection containing the values in the Hashtable Hashtable.Values Property is used to get an ICollection containing the values in the Hashtable. Syntax: public virtual System.Collections.ICollection Values { get; } Return Value: This property returns an ICollection containing the values in the Hashtable. Note: The order of values in the ICollectio 2 min read C# | How to get the HashCode for the string GetHashCode() method is used to get the hash code of the specified string. When you apply this method to the string this method will return a 32-bit signed integer hash code of the given string. Syntax: public override int GetHashCode (); Return Value: The return type of this method is System.Int32. 2 min read C# | Getting the index of the specified key in a SortedList object SortedList.IndexOfKey(Object) Method is used to get the zero-based index of the specified key in a SortedList object. Syntax: public virtual int IndexOfKey (object key); Here, key is the Key which is to be located in the SortedList object. Return Value: This method returns the zero-based index of ty 3 min read Finding the Index of First Element of the Specified Sequence in C# The Index Structure is introduced in C# 8.0. It represents a type that can be used to index a collection or sequence and it can be started from the start or the end. You are allowed to find the index, which points the first element of the specified collection or sequence with the help of Start Prope 2 min read Creating an Index From the Specified Index at the Start of a Collection in C# The Index Structure is introduced in C# 8.0. It represents a type that can be used to index a collection or sequence and it can be started from the start or the end. You are allowed to create a start index with the help of the FromStart(Int32) Method() provided by the Index struct. This method retur 2 min read Like