C # Group Tuple

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.