Tuple
is said to have been introduced to .NET 4 because some programming languages (let's say, for example, IronPython or F#) support tuples as a core feature of the language, and the .NET BCL team wanted to provide a uniform tuple type for such languages (for language interoperability reasons, I guess):
The BCL team decided to work with the F# team to standardize on one tuple type for the framework so that every language could benefit from them. (in Eric Lippert's answer to the SO question, What problem was the tuple designed to solve?
)
Tuple
does not make much sense in the C# language IMHO, because C# doesn't support tuples and some associated language constructs very well; e.g. tuple "explosion": spreading a tuple over a function's parameters, or taking a function's return values (in the form of a Tuple
) and spreading it over several local variables:
Tuple<int,int> GetFoo() { … }
// v v
int (a, b) = GetFoo(); // C# doesn't support this tuple-related syntax.
That being said, if you're writing only C# code, you can usually find "better", more structured solutions than using Tuple
. For example, using tuples to return more than one value from a method (such as in GetFoo
above) is quick and convenient, but the return value doesn't have any inherent structure — you might do better with a struct
or class
type, if you're willing to take some additional time to define it.