What's the best way of using a pair (triple, etc) of values as one value in C#?
- by Yacoder
That is, I'd like to have a tuple of values.
The use case on my mind:
Dictionary<Pair<string, int>, object>
or
Dictionary<Triple<string, int, int>, object>
Are there built-in types like Pair or Triple? Or what's the best way of implementing it?
Update There are some general-purpose tuples implementations described in the answers, but for tuples used as keys in dictionaries you should additionaly verify correct calculation of the hash code. Some more info on that in another question.
Update 2 I guess it is also worth reminding, that when you use some value as a key in dictionary, it should be immutable.