C#中的多重字典(另一种)? [英] Multi-key dictionaries (of another kind) in C#?

查看:244
本文介绍了C#中的多重字典(另一种)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于这个问题,是否有一个简单的解决方案,

Building on this question, is there a simple solution for having a multi-key dictionary where either key individually can be used to identify the value?

ie

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 seems to detail a rather decent implementation.


C#的多键通用字典类



MultiKeyDictionary是一个C#class
,它包装并扩展

提供的Dictionary对象.NET 2.0及以上版本。这个
允许开发人员创建一个通用的
字典的值,并通过两个键而不是
引用
值列表,只是由Microsoft
实现提供的一个Generic
字典< ...>。你可以在CodeProject(这里)看到我的
文章,但是
这个代码是更新的,而且
是免费的。

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#中的多重字典(另一种)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆