views:

121

answers:

2

Is there a built in object that handles 3 linked values in a similar fashion to the hashtable? i.e. Key, Value1, Value2?

+3  A: 

You could easily make one using a generic dictionary. Something like Dictionary<Key, KeyValuePair<Key, Value>>, or even Dictionary<Key, object[]>

Mike_G
I thought about that - this library wasn't supposed to be heavy duty though so I was hoping not to have to build/implement anything extensive.
BenAlabaster
Im not quite sure I understand. Dictionary and KeyValuePair are already implemented in .NET. You wouldnt have to build anything.
Mike_G
Oops - I guess your whole text didn't post before I was commenting... yes, I see what you're getting at.
BenAlabaster
I agree with Mike_G that this is probably the quickest way to implement what you want; but it probably won't yield the most maintainable code. In my experience, having a custom class as your "Value" with well named properties will be a lot clearer to people looking at your code for the first time.
Antony Perkov
Don't like the object[] route, but +1 for KeyValuePair. There's a non generic Pair class somewhere in the BCL that I also use occasionally, but all I recall is that it's somewhere in one of the Control namespaces (WebControl, Control, ComponentModel or something...)
Mark Brackett
Ya, object[] was just continue the example that the value in the dictionary could really be anything that can hold 2 values
Mike_G
+5  A: 

I would have said generic dictionary too.

If you didn't want to do anything extensive, just make a struct or some sort of tuple out of Value1, Value2 and make those the value of your dictionary's Key. Something like:

Dictionary<Key, ThatTinyStructYouHadToCreate>

Bad idea: If you didn't like that option, as far as "built-in" goes, a DataRow in a DataTable would give you that ability. While that's a very simple way to set it up, it'd also be a remarkably inefficient (as far as execution cost) way to go about it.

joshua.ewer
I was going to suggest this, nice.
bendewey