基于 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# - C# 中的多键字典(另一种)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1171913/