微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.

原文地址:https://www.jb51.cc/csharp/95676.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐