C # group meta Tuple

Source: Internet
Author: User

C # group meta Tuple

Group Meta is a new feature introduced by C #4.0. It must be Based on. NET Framework 4.0 or later. Group elements use generics to simplify the definition of a class. Group elements are mostly used

Method return value. If a function returns multiple types, it does not use output parameters such as out \ ref. You can directly define a Tuple type.


1.0 simple use


// A member Tuple
 
  
Test = new Tuple
  
   
(1); Console. WriteLine (test. Item1); // two members, Tuple
   
    
Test1 = new Tuple
    
     
(2, 2.3); Console. WriteLine (test1.Item1 + test1.Item2 );
    
   
  
 

2.0 nested use


TupleA maximum of 8 members are supported.If there are more than eight, nesting is required.

Note that 8th members are special. 8th members must be nested into the Tuple type.


// Non-8 elements, Tuple
 
  
> Test2 = new Tuple
  
   
> (3, new Tuple
   
    
("Nesting"); Console. WriteLine (test2.Item1); Console. WriteLine (test2.Item2); // eight elements Tuple
    
     
> Test3 = new Tuple
     
      
> (1, 2, 3.0f, 4, 5, 6, 'h', new Tuple
      
        (8); Console. WriteLine (test3.Item1 + test3.Rest. Item1 );
      
     
    
   
  
 


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.