Articles → CSHARP → Tuples In C#
Tuples In C#
Purpose
How To Declare A Tuple?
- Passing the value in the constructor of the tuple class
- Using the Create method
Tuple<string, string, int> person = new Tuple< string, string, int>("sumit", "sharma", 45);
Tuple<string, string, int> anotherPerson = Tuple.Create("sumit", "sharma", 45);
How Many Parameters Can Be Passed Inside The Create Method
Accessing The Tuple Element
var tuple = Tuple.Create(1,2,3,4,5,6,7,8);
// Accessing the elements
Console.WriteLine(tuple.Item1);
Console.WriteLine(tuple.Item2);
Console.WriteLine(tuple.Item3);
Console.WriteLine(tuple.Item4);
Console.WriteLine(tuple.Item5);
Console.WriteLine(tuple.Item6);
Console.WriteLine(tuple.Item7);
Console.ReadLine();
Click to Enlarge