Click here to Skip to main content
13,353,124 members (66,554 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 4 Jul 2011

MultiKeyDictionary generic class.

, 5 Jul 2011
Rate this:
Please Sign up or sign in to vote.


Dictionary<TKey, TValue> class allows only one object to serve as a key for its key/value element. But there are situations that require the key to consist of more than one entity.

The MultiKeyDictionary<TKey1, TKey2, TValue> class implements Dictionary<TKey, TValue>-like functionality, but unlike Dictionary<TKey, TValue> each key consists of two parts.


MultiKeyDictionary<TKey1, TKey2, TValue> class is one of several classes implemented in my POSOlSoft.MultiKeyDictionary free .NET component.

Using the Code

Members of the MultiKeyDictionary<TKey1, TKey2, TValue> class are described in the XML documentation contained in the source code.

Usage of the MultiKeyDictionary<TKey1, TKey2, TValue> class is very similar to the Dictionary<TKey, TValue> class usage and is quite straightforward:

MultiKeyDictionary<string, string, int> mkd = new MultiKeyDictionary<string, string, int>();
mkd.Add( "one", "two", 3 );
mkd[ "four", "five" ] = 6;
Console.WriteLine( mkd.Count );
Console.WriteLine( mkd[ "one", "two" ] );
foreach ( var e in mkd )
  Console.WriteLine( e );

Points of Interest

Functionality implemented by the MultiKeyDictionary<TKey1, TKey2, TValue> class is similar to functionality of the Dictionary<Tuple<TKey1, TKey2>, TValue> class. But MultiKeyDictionary<TKey1, TKey2, TValue> class is much faster.

Performance comparison of MultiKeyDictionary<TKey1, TKey2, TValue> class against Dictionary<Tuple<TKey1, TKey2>, TValue> class may be found here:


4 July 2011 - first version.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Oleg Subachev
Founder POSOlSoft
Russian Federation Russian Federation
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralReason for my vote of 1 Plagiarized. Pin
Aron Weiler21-Feb-12 9:16
memberAron Weiler21-Feb-12 9:16 
GeneralReason for my vote of 5 Interesting tip! There is actually t... Pin
DrABELL4-Jul-11 11:16
memberDrABELL4-Jul-11 11:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 5 Jul 2011
Article Copyright 2011 by Oleg Subachev
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid