Tuple, a new data structure in C#
Tuple is an interesting data structure in C#. It contains number and sequence. You can create tuple of 1 to 7 elements. Additionally you can create tuple of eight element using the TRest element. TRest element allows you to add nested tuple.
Let see example of basic tuple. We have student entity having marks fro seven subject. We can define this data structure by using tuple.
var tupleStudent = Tuple.Create("Mandar Badve", 87, 45, 76, 78, 64, 71, 80);
Console.WriteLine(""+ tupleStudent.Item1 + " got " + tupleStudent.Item2 + " marks in first subject.");
//// OUTPUT: Mandar Badve got 87 marks in first subject.
Console.WriteLine(""+ tupleStudent.Item1 + " got " + tupleStudent.Rest.Item1 + " marks in seventh subject.");
//// OUTPUT: Mandar Badve got 80 marks in seventh subject.
For more information visit http://blog.mandarbadve.com/2016/01/20/tuple-a-new-data-structure-in-c/