Can someone please explain what's the real use of a Tuple ?
You can think of tuples as being a bit like anonymous types, but without the names - and with the ability to specify return types etc. They're useful when you want an ad hoc multi-value data type, but want to be able to specify that as the return type of a method.
For example, int.TryParse
could have had a signature of
static Tuple<int, bool> TryParse(string text)
Basically you want to return an int
and a bool
. The existing signature uses an out
parameter to get around the fact that you can only return a single value - tuples are another option. Likewise KeyValuePair<TKey, TValue>
is basically just a pair of values.
Personally I'd like to see another option: a terse way of achieving the semantics of anonymous types (immutability, named properties, equality etc), but with a name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With