Dictionary<TKey, TValue>
is great for doing fast lookups using the strongly-typed key; sometimes, however, I need to do lookups based on a unique combination of two (or more) variables. My "design pattern" for accomplishing this is to concatenate the values together using a separator, like this:
String compoundKey = productID.ToString + "~" + colorID.ToString;
myDict.Add(compoundKey, myObject);
This method seems a bit hacky. This answer uses a struct
but I'm not convinced that it is any better.
What is the preferable way of making dictionaries work with compound keys?