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 );
}
}