Tuples in c#
Posted By :
Bipul Kumar Tiwari,
A tuple is a data structure that has a specific number and sequence of elements. It is an ordered sequence, immutable, fixed size of heterogeneous objects.
Ordered sequence:
The order of items in a tuple follows the order used at the time of its creation.
Immutable:
All properties are read-only tuple, i.e., once created, it cannot be changed.
Fixed Size:
The size is set at the time of its creation. If it was created with three items, you cannot add new items.
heterogeneous objects:
Each item has a specific and independent of the type of the other item.
Tuples are commonly used in four ways:
- To represent a single set of data.
- To provide easy access to, and manipulation of, a data set.
- To return multiple values from a method without using out parameters
- To pass multiple values to a method through a single parameter.
The static class Tuple provides 8 overloads Create methods to create Tuple of size 1 to 8.
Methods Name
|
Description
|
Create<T1>(T1) |
Create a new 1-tuple, or singleton. |
Create<T1, T2>(T1, T2) |
Create a new 2-tuple, or pair. |
Create<T1, T2, T3>(T1, T2, T3) |
Create a new 3-tuple, or triple. |
Create<T1, T2, T3, T4>(T1, T2, T3, T4) |
Create a new 4-tuple, or quadruple. |
Create<T1, T2, T3, T4, T5>(T1, T2, T3, T4, T5) |
Create a new 5-tuple, or quintuple. |
Create<T1, T2, T3, T4, T5, T6>(T1, T2, T3, T4, T5, T6) |
Create a new 6-tuple, or sextuple. |
Create<T1, T2, T3, T4, T5, T6, T7>(T1, T2, T3, T4, T5, T6, T7) |
Create a new 7-tuple, or septuple. |
Create<T1, T2, T3, T4, T5, T6, T7, T8>(T1, T2, T3, T4, T5, T6, T7, T8) |
Create a new 8-tuple, or octuple. |