Tutorial by Examples

Tuples are created using generic types Tuple<T1>-Tuple<T1,T2,T3,T4,T5,T6,T7,T8>. Each of the types represents a tuple containing 1 to 8 elements. Elements can be of different types. // tuple with 4 elements var tuple = new Tuple<string, int, bool, MyClass>("foo", 123, t...
To access tuple elements use Item1-Item8 properties. Only the properties with index number less or equal to tuple size are going to be available (i.e. one cannot access Item3 property in Tuple<T1,T2>). var tuple = new Tuple<string, int, bool, MyClass>("foo", 123, true, new MyC...
Tuples can be compared based on their elements. As an example, an enumerable whose elements are of type Tuple can be sorted based on comparisons operators defined on a specified element: List<Tuple<int, string>> list = new List<Tuple<int, string>>(); list.Add(new Tuple<...
Tuples can be used to return multiple values from a method without using out parameters. In the following example AddMultiply is used to return two values (sum, product). void Write() { var result = AddMultiply(25, 28); Console.WriteLine(result.Item1); Console.WriteLine(result.Item2...

Page 1 of 1