How to compare two ValueTuple in C#? Last Updated : 23 Jul, 2019 Comments Improve Suggest changes Like Article Like Report To compare two instances of ValueTuple you can use CompareTo method which is provided by ValueTuple structure. ValueTuple.CompareTo(ValueTuple) Method is used to compare the current instance of ValueTuple with another ValueTuple instance. It always returns zero if they are equal to each other. Syntax: public int CompareTo (ValueTuple other); Here, other is the object to compare with the current instance. Returns: The method always returns 0 of type System.Int32. Exception: This method will throw an ArgumentException if the other is not ValueTuple instance. Example 1: CSharp // C# program to illustrate the // concept of CompareTo method using System; class GFG { // Main method static public void Main() { // Creating value tuples with two elements var MyTple1 = ValueTuple.Create(56, 45); var MyTple2 = ValueTuple.Create(56, 3); var MyTple3 = ValueTuple.Create(56, 45); var MyTple4 = ValueTuple.Create(5345, 45); // Using CompareTo method int res1 = MyTple1.CompareTo(MyTple2); int res2 = MyTple1.CompareTo(MyTple3); int res3 = MyTple1.CompareTo(MyTple4); // Display result Console.WriteLine("Result 1: " + res1); Console.WriteLine("Result 2: " + res2); Console.WriteLine("Result 3: " + res3); } } Output: Result 1: 1 Result 2: 0 Result 3: -1 Example 2: CSharp // C# program to illustrate the // use of CompareTo method using System; class GFG { // Main Method static public void Main() { // Creating value tuples with one element var MyVTple1 = ValueTuple.Create(2018); var MyVTple2 = ValueTuple.Create(2018); // Compare both value tuples // Using CompareTo method if (MyVTple1.CompareTo(MyVTple2) == 0) { Console.WriteLine("Welcome to GeeksforGeeks"); } else { Console.WriteLine("Page Not Found"); } } } Output: Welcome to GeeksforGeeks Reference: https://docs.microsoft.com/en-us/dotnet/api/system.valuetuple.compareto?view=netframework-4.8 Comment More infoAdvertise with us Next Article How to compare two ValueTuple in C#? A ankita_saini Follow Improve Article Tags : C# CSharp-ValueTuple CSharp-ValueTuple-Methods Similar Reads Comparing two ValueTuple<T1> in C# ValueTuple is a structure introduced in C# 7.0 which represents the value type Tuple. It is already included in .NET Framework 4.7 or higher version. It allows you to store a data set that contains multiple values that may or may not be related to each other. You can also compare the instance of two 2 min read Comparing two ValueTuple<T1, T2> in C# ValueTuple is a structure introduced in C# 7.0 which represents the value type Tuple. It is already included in .NET Framework 4.7 or higher version. It allows you to store a data set that contains multiple values that may or may not be related to each other. You can also compare the instance of two 2 min read How to compare Enum values in C#? Enum.CompareTo(Object) Method is used to compare the current instance to a specified object and returns an indication of their relative values. Syntax: public int CompareTo (object target); Here, the target is an object to compare or it may be null. Returns: This method returns a signed number which 2 min read Comparing two ValueTuple<T1, T2, T3> in C# ValueTuple is a structure introduced in C# 7.0 which represents the value type Tuple. It is already included in .NET Framework 4.7 or higher version. It allows you to store a data set that contains multiple values that may or may not be related to each other. You can also compare the instance of two 2 min read Comparing two ValueTuple<T1, T2, T3, T4> in C# ValueTuple is a structure introduced in C# 7.0 which represents the value type Tuple. It is already included in .NET Framework 4.7 or higher version. It allows you to store a data set that contains multiple values that may or may not be related to each other. You can also compare the instance of two 2 min read Like