In C#, a ValueTuple
#Before we dive in, it's important to understand what a ValueTuple
This is an example of ValueTuple
ValueTuple<int> valueTuple = new ValueTuple<int>(1);
In this example, valueTuple is an instance of ValueTuple
In C#, you can directly use the == operator or the Equals method to check whether two ValueTuple
This is an example using the == operator -
using System; class Program { static void Main() { Tuple<int> valueTuple1 = Tuple.Create(1); Tuple<int> valueTuple2 = Tuple.Create(1); if (valueTuple1.Equals(valueTuple2)) { Console.WriteLine("ValueTuples are equal."); } else { Console.WriteLine("ValueTuples are not equal."); } } }
ValueTuples are equal.
This is an example using the Equals method -
using System; class Program { static void Main() { Tuple<int> valueTuple1 = Tuple.Create(1); Tuple<int> valueTuple2 = Tuple.Create(1); if (valueTuple1.Item1 == valueTuple2.Item1) { Console.WriteLine("ValueTuples are equal."); } else { Console.WriteLine("ValueTuples are not equal."); } } }
In these examples, we create two ValueTuple
ValueTuples are equal.
ValueTuple
The above is the detailed content of Compare two ValueTuple T1 in C#. For more information, please follow other related articles on the PHP Chinese website!