I just published an article on a generic Trictionary class :
The article describes a Trictionary class that is essentially a dictionary except that for each key there are two values, both of differing types. In many cases instead of doing this, the proper approach would most likely to use a struct that would have those two types as members. But there may also be scenarios where you may want to avoid having to unnecessarily create a struct just for this purpose. You could also use an anonymous type, but that’s really not so different in the sense you still end up having a new type in your assembly. Read the article for more info.
Note that the article was inspired by another Trictionary article on Code Project submitted by Joe Enos.
Hi Nish,
for this, I usually use a Dictionary<T, KeyValuePair>
I don’t like to create a class that acts only as a container, if I can avoid this …
Yep, or you can use the Pair<> struct. But neither Pair nor KeyValuePair support implicit conversions. So you cannot do :
tric[x] = “string”; // string
tric[x] = 25; // Int32
string s = tric[x];
int i = tric[x];
Hi Nish,
Sorry, but I dont find Trictionary a very bright idea… What’s next? Fourdictionary?
How about using Tuple in .NET 4.0?