c# - C# 中的多键字典(另一种)?

标签 c# data-structures

基于 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/

相关文章:

c# - 没有 Visual Studio 的 C# 中的 GUI

c# - 避免 resx 文件中的合并冲突

perl - 向数组散列中的数组添加新元素

谁能帮助我编写图书馆目录 C 程序?

c# - Entity Framework 4 SaveChanges 内存不足

c# - Visual Studio 在线销毁文件

algorithm - 递归算法的时间复杂度

python - 多路树和结构

java - 网络流量 : Adding a new edge

javascript - 将 .net 核心模型数据传递给外部 javascript?