See Also: Tuple<T1,T2> Members
- T1
- Documentation for this section has not yet been entered.
- T2
- Documentation for this section has not yet been entered.
A tuple is a data structure that has a specific number and sequence of values. The Tuple`2 class represents a 2-tuple, or pair, which is a tuple that has two components. A 2-tuple is similar to a KeyValuePair`2 structure.
You can instantiate a Tuple`2 object by calling either the Tuple`2.#ctor(`0, `1) constructor or the static Tuple.Create``2(``0, ``1) method. You can retrieve the values of the tuple's components by using the read-only Tuple`2.Item1 and Tuple`2.Item2 instance properties.
Tuples are commonly used in four different ways:
To represent a single set of data. For example, a tuple can represent a record in a database, and its components can represent that record's fields.
To provide easy access to, and manipulation of, a data set. The following example defines an array of Tuple`2 objects that contain the names of students and their corresponding test scores. It then iterates the array to calculate the mean test score.
code reference: System.Tuple`2.Class#1
To return multiple values from a method without the use of out parameters (in C#) or ByRef parameters (in Visual Basic). For example, the following example uses a Tuple`2 object to return the quotient and the remainder that result from integer division.
code reference: System.Tuple`2.Item1#1
To pass multiple values to a method through a single parameter. For example, the System.Threading.Thread.Start(object) method has a single parameter that lets you supply one value to the method that the thread executes at startup. If you supply a Tuple`2 object as the method argument, you can supply the thread’s startup routine with two items of data.