Article : A generic Trictionary class

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.

Advertisements

4 thoughts on “Article : A generic Trictionary class

  1. 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 …

  2. 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];

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s