![]() |
VOOZH | about |
In C#, the Tuple class is used to provide static methods for creating tuples and this class is defined under the System namespace. This class itself does not represent a tuple, but it provides static methods that are used to create an instance of the tuple type. In other words, the Tuple class provides helper methods that are used to instantiate tuple objects without having to explicitly specify the type of each tuple component. In tuple, we can only store elements from one to eight, if you try to store elements greater than eight without a nested tuple, then the compiler will give an error. There are some key uses of tuples which are mentioned below:
Note: We can create a tuple with the help of the constructors which are provided by tuple classes, but in constructors, you have to specify the type of the elements present in the tuple.
Example: Creating a tuple using tuple constructor.
Element 1: 22 Element 2: 33 Element 3: 54 Element 4: 65 Element 5: 76 Element 6: 87 Element 7: 98
We have different methods to create tuples with exact element numbers up to eight.
Method | Description |
|---|---|
Creates a new 1-tuple, or singleton | |
Creates a new 2-tuple, or pair. | |
Creates a new 3-tuple, or triple. | |
Creates a new 4-tuple, or quadruple. | |
Creates a new 5-tuple, or quintuple. | |
Creates a new 6-tuple, or sextuple. | |
reate <T1, T2, T3, T4, T5, T6, T7>(T1, T2, T3, T4, T5, T6, T7) | Creates a new 7-tuple, or septuple. |
Create <T1, T2, T3, T4, T5, T6, T7, TRest>(T1, T2, T3, T4, T5, T6, T7, T8) | Creates a new 8-tuple, or octuple. |
Example:
Element 1: Geeks Element 2: 2323 Element 3: g