Can someone please explain what’s the real use of a Tuple ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.TryParsecould have had a signature ofBasically you want to return an
intand abool. The existing signature uses anoutparameter to get around the fact that you can only return a single value – tuples are another option. LikewiseKeyValuePair<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.