What's the best way of using a pair (triple, etc) of values as one value in C#?

Posted by Yacoder on Stack Overflow See other posts from Stack Overflow or by Yacoder
Published on 2008-09-19T13:31:14Z Indexed on 2010/04/01 18:03 UTC
Read the original article Hit count: 250

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics