Tuples

From The Oxygene Language Wiki

Jump to:navigation, search

This is a Language topic
Feel free to add your notes to this topic below.


.NET 4.0 introduces a new set of types called Tuple.

Tuples are fixed size collections of differently typed elements. They can be used as result types to return multiple return values at once, or as a parameter. This allows to avoid creating custom types when, for example, a method has to return two values of different types (for example an Integer and a String) at once.

The Tuple type is a set of generic types with 1 up to 7 generic parameter types for the value types. There also is an 8th Tuple type of which the 8th parameter type has to be another tuple. This last tuple can be used to create tuples of sizes larger than 7. All tuples are comparable (IComparable), implement the Equals and GetHashCode methods based on their elements, as well as the IStructuralEquatable and IStructuralComparable interfaces.

In addition to the actual type, Delphi Prism supports assigning open array expressions to a tuple type:

method GetFirstTwo<T1,T2,T3>(aTuple: Tuple<T1, T2, T3>): Tuple<T1, T2>;
begin
  result := [aTuple.Item1, aTuple.Item2];
end


Oxygene-48.png

Area: Oxygene Language
Compiler version: Oxygene 5

Language GlossaryKeywordsTypesFAQHow To

Navigation
Areas
More
Toolbox