The tuple is a new feature introduced by C # 4.0. You need to base the. NET Framework 4.0 or later. A tuple uses generics to simplify the definition of a class. The tuple is used more for
The return value of the method, if a function returns more than one type, so it is not used for output parameters such as Out\ref, you can define a tuple type directly.
1.0 Easy to use
A member Tuple<int> test = new tuple<int> (1); Console.WriteLine (Test. ITEM1);//Two members Tuple<int, double> test1 = new Tuple<int, double> (2, 2.3); Console.WriteLine (test1. Item1 + test1. ITEM2);
2.0 Nesting Use
A Tuple supports up to 8 members , and if more than 8, it needs to be nested.
Note that the 8th member is special, and the 8th member must be nested defined as a tuple type
Non-8 elements tuple<int, tuple<string>> test2 = new Tuple<int, tuple<string>> (3, New tuple<string > ("Nesting")); Console.WriteLine (test2. ITEM1); Console.WriteLine (test2. ITEM2);//8 elements tuple<int, long, float, double, short, Byte, char, tuple<int>> test3 = new Tuple<int, Lon g, float, double, short, Byte, Char, tuple<int>> (1, 2, 3.0f, 4, 5, 6, ' H ', new tuple<int> (8)); Console.WriteLine (Test3. Item1 + test3. REST.ITEM1);
C # Group Tuple