tags:

views:

177

answers:

3

Possible Duplicate:
Multi value Dictionary

I just need to store 2 value. How can I do that?

+2  A: 

Multi value Dictionary

CD
Thanks i did not find that when I search.
Jonathan Shepherd
A: 

If you need variable number of values per key, you can use

Dictionary<TypeOfKey, List<TypeOfValue>

E.g. if you want to store an arbitrary number of integers per string, you could do this

var numbersPerString = new Dictionary<string, List<int>>();
Brian Rasmussen
A: 

Dictionary values can be an arbitrary type, so make the values structs with appropriate members, then you'll be able to store two, or as many as you like.

I don't know if C# has an equivalent to C++ std::pair; you could use that, but a struct might make more sense, then you can say:

dict[person].shoesize
dict[person].eyecolour

Which is nice and readable.

MarkR