C # example of yuanzu tuple

Source: Internet
Author: User

The array merges objects of the same type, while the ancestor merges objects of different types. The ancestor originated from the function programming language (F #)
Net Framework defines eight generic tuple (from net4.0) and a static tuple class. They act on the factory of the original ancestor,
Different generic tuple classes support different numbers of elements. For example, tuple <t1> contains one element, tuple <T1, T2> contains two elements, and so on.

 

/* Creator: the blog of caidao jushi
* Creation date: January 1, July 14, 2014
*/

Namespace net. String. consoleapplication
{
Using system;

/// <Summary>
/// Ancestor tuple
/// </Summary>
Public class tupledemo
{
/// <Summary>
/// The devide method returns the tuple, the ancestor of two members <int, int>. The parameter of the generic class defines the type of the member, and they are all integers.
/// The ancestor is created using the static create method of the static tuple class. The generic parameters of the create method define the ancestor type to be instantiated.
/// The new ancestor is instantiated using the resulta and resultb variables.
/// </Summary>
Public static tuple <int, int> devide (int A, int B)
{
Int resulta = A/B;
Int resultb = A % B;

Return tuple. Create (resulta, resultb );
}

/// <Summary>
/// Call the devide method. You can use the Item1 and item2 attributes to access the items of the ancestor.
/// </Summary>
Public static void test ()
{
VaR result = devide (10, 2 );
Console. writeline ("Resulta: {0}, resultb: {1}", result. Item1, result. item2 );
}

// If the ancestor contains more than eight items, the tuple class of the eight parameters can be used for definition. The trest of the last template parameter indicates that a ancestor must be passed to him.
// In this way, you can create the ancestor of any parameter

// Public static tuple <T1, T2, T3, T4, T5, T6, T7, tuple <T8> Create <T1, T2, T3, T4, T5, T6,
// T7, T8> (T1 Item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, T8 item8 );
}
}

 

 

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.