What is Tuple and when it was introduced?
A Tuple is a new data type introduced from .Net Framework 4.0. When there is a requirement to store multiple values of different data types, then we can go with Tuple. Simply “Tuple is a container of values with similar or different data type which supports 7 items (similar/different data types) plus 1 Tuple type”. Point to be noted here is, it is not a collection.
When to use Tuple?
Tuple can use to store any single set of data. We have few specific scenarios where only a Tuple can serve.
Scenario1
Generally, a method can return at most two values including out parameter. When we want to return more than two values without having to create any separate class, then we can use Tuple and Vice versa.
Scenario2
We have a requirement to fetch a single row from the database every time and need to handle data without more efforts. This situation can manage with Tuple by assigning values to Tuple.
We can declare a Tuple as follows.
- //Single valued Tuple
- Tuple<int> TupleObjectName;
- //Double valued Tuple
- Tuple<int,string> TupleObjectName;
Syntax
Tuple<T1, T2>
Tuple<T1, T2, T3>
Tuple<T1, T2, T3, T4>
Tuple<T1, T2, T3, T4, T5>
Tuple<T1, T2, T3, T4, T5, T6>
Tuple<T1, T2, T3, T4, T5, T6, T7>
Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>
Here, T can be any type and TRest is a Tuple type.
If you have seen it, while declaring a tuple, you will get 8 override functions, as shown below.

In the last override method, we can add 7 types with one Tuple type (I will explain in detail with an example).
Let’s assume, we have declared a tuple as follows.
- Tuple<int, int, int, double> ArithmeticResult;
Method 1
- ArithmeticResult = new Tuple<int, int, int, double> (1, 1, 2, 1.11);
Method 2
- ArithmeticResult = Tuple.Create(1, 1, 1, 2.2);
Tuple.create() vs new Tuple
See the following example .
- //Tuple with 8 items with one Tuple type
- Tuple<int, int, int, int, int, int, int, Tuple<int, int>> dataWithEightarguments;
- //Preparing a Tuple for 8th item
- Tuple<int, int> innerData = Tuple.Create(2, 3);
- //Assigning value with New Tuple Syntax-- No error
- dataWithEightarguments = new Tuple<int, int, int, int, int, int, int, Tuple<int, int>>(2, 2, 2, 2, 2, 2, 2, innerData);
- //Assigning value with Tuple.Create() -- Will get Compilation error
- dataWithEightarguments = Tuple.Create(1, 1, 1, 1, 1, 1, 1, innerData);

Join the conversation! Your thoughts help the community grow.