加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 06:24:56 所属栏目:百科 来源:网络整理
导读:建立在 this question,是否有一个简单的解决方案,有一个多键字典,其中任何一个键可以用来识别价值? 即. MultikeyDictionaryTKey1,TKey2,TValue foo;foo.Add(key1,key2,value);myValue = foo[key1];// value == myValuefoo.Remove(key2);myValue = foo[key1]
建立在 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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读