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

前端之家收集整理的这篇文章主要介绍了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.

猜你在找的C#相关文章