重复在.NET词典按键? [英] Duplicate keys in .NET dictionaries?

查看:88
本文介绍了重复在.NET词典按键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何字典类在.NET基础类库,允许重复键使用?我发现的唯一的解决办法是创建,例如,一类这样的:

Are there any dictionary classes in the .NET base class library which allow duplicate keys to be used? The only solution I've found is to create, for example, a class like:

Dictionary<string, List<object>>

但是,这是相当刺激性的实际使用。在Java中,我相信一个multimap中完成这一点,但无法找到在.NET中模拟。

But this is quite irritating to actually use. In Java, I believe a MultiMap accomplishes this, but cannot find an analog in .NET.

推荐答案

如果您使用的是.NET 3.5,使用的 查找 类。

If you're using .NET 3.5, use the Lookup class.

编辑:通常你创建一个查找使用<一个href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.tolookup.aspx"><$c$c>Enumerable.ToLookup.这并不认为你不需要事后改变它 - 但我通常会发现这是不够好

You generally create a Lookup using Enumerable.ToLookup. This does assume that you don't need to change it afterwards - but I typically find that's good enough.

如果说的的为你工作,我不认为有什么事的框架,这将有助于 - 并使用字典是爱在心里口难开:(

If that doesn't work for you, I don't think there's anything in the framework which will help - and using the dictionary is as good as it gets :(

这篇关于重复在.NET词典按键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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