tags:

views:

52

answers:

2

I've got a data structure that is Key, Value, OtherValues(key, Value). So the OtherValues are attached to the first Key and aren't always there. I can do this as Dictionary<Key, ValueAndListOfOptionalValues> where ValueAndListOfOptionalValues is a class with a string and a Dictionary<string, string>.

I'm wondering if that's really the best way to do it? Sometimes I think that I'm missing some important classes in the Generics namespace, maybe there are better classes out there that I'm not aware of.

+1  A: 

I think that is a perfectly acceptable solution. As long as you will never need to look up anything from OtherValues from the main Dictionary this should work fine and not incur any performance issues.

Andrew Hare
+1  A: 

I, personally, would use your "custom class" approach.

However, if you want to avoid a custom class (even though there's no reason to avoid it) you could do:

 Dictionary<string, KeyValuePair<string,Dictionary<string,string>>>

It's just awfully ugly...

Reed Copsey
Good point, I've got to consider code readability too. Just because you can do it in one line doesn't mean you should.
jcollum
Yeah - this works, but it's really, really ugly. I'd refactor this into a custom class ASAP, if it were my code.
Reed Copsey