Tuple Class in C#


If you want to return more than one value from a class method, then use C# Tuples. To create tuples in C#< this class provides a static method. Tuples introduced in .NET 4.0.

Example

Let us now see an example to implement Tuple in C# −

using System;
public class Demo {
   public static void Main(string[] args) {
      Tuple<int, string> tuple = new Tuple<int, string>(2, "Tom");
      if (tuple.Item1 == 150) {
         Console.WriteLine(tuple.Item1);
      }
      if (tuple.Item2 == "Tom") {
         Console.WriteLine(tuple.Item2);
      }
   }
}

Output

This will produce the following output −

Tom

Updated on: 05-Nov-2019

135 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements