字典有重复键 [英] Dictionary with duplicate Key

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

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/551901/is-there-an-alternative-to-dictionary-sortedlist-that-allows-duplicates">Is有替代字典/排序列表,允许重复?

我要寻找一个字典排序类的,可以有重复的钥匙。

I am looking for a Dictionary sort of class which can have duplicate Keys.

我搜索一下,发现的查找类可以用来存储重复键,但是它没有默认构造函数,因此,没有任何其他对象来查找我们不能对其进行初始化。

I search about it, and found LookUp class can use to store duplicate keys, but It has no default constructor, So we can't initialize it without any other object to LookUp.

但我一开始没有任何这样的对象从中我可以初始化一个Lookup对象。

But I have no any such object initially from which I can initialize a LookUp object.

所以,我的问题是,是否有任何类在.NET Framework 3.5的,其行为类似于字典,但让我有重复的按键,例如查找?

So, My question is, Is there any class in .Net framework 3.5, which behave like Dictionary but allow me to have duplicate keys like LookUp?

推荐答案

一个字典,根据定义,将永远无法拥有多个密钥。 (如果你抬头看任何会返回一个关键?)即使是查找,你是指,不允许它。你的什么可以的要做的就是让每个按键对应的多个值的(逻辑上,而不是技术上的)。这是通过具有词典中,它的数值是某种类型的数据结构进行(例如,一个列表),它包含所有对应于该特定键的值的

A Dictionary, by definition, will never be able to have multiple keys. (If you looked up a key whatever would you return?) Even a Lookup, which you refer to, doesn't allow it. What you can do is have each key refer to multiple values (logically, not technically). This is done by having a dictionary in which the value is a data structure of some sort (for example, a List) that contains all of the values that correspond to that particular key.

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

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