C#中的多重字典(另一种)?

建立在 this question,是否有一个简单的解决方案,有一个多键字典,其中任何一个键可以用来识别价值?

即.

multikeyDictionary<TKey1,TKey2,TValue> foo;
foo.Add(key1,key2,value);
myValue = foo[key1];
// value == myValue
foo.Remove(key2);
myValue = foo[key1]; // invalid,Exception or null returned

解决方法

This blog post似乎详细描述了一个相当体面的实现.

Multi-key generic dictionary class for C#

multikeyDictionary is a C# class that wraps and extends the Generic Dictionary object provided by Microsoft in .NET 2.0 and above. This allows a developer to create a generic dictionary of values and reference the value list through two keys instead of just the one provided by the Microsoft implementation of the Generic Dictionary<…>. You can see my article on CodeProject (here),however this code is more up-to-date and bug free.

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...