内容简介:我正在寻找一个类似于字典的数据结构,它将所有相关项的集合返回给一个键.例如,我会像这样使用它:在这个例子中,alternateNames1将是一个包含“Liz”和“Elizabeth”的数组,alternateNames2将是一个包含“Elizabeth”和“Betty”的数组.
我正在寻找一个类似于字典的数据结构,它将所有相关项的集合返回给一个键.
例如,我会像这样使用它:
var data = new FancyDataStructure();
data.Add(new string[] {"Elizabeth", "Liz", "Betty"});
data.Add(new string[] {"Bob", "Robert", "Rob"});
string[] alternateNames1 = data["Betty"];
string[] alternateNames2 = data["Liz"]
在这个例子中,alternateNames1将是一个包含“Liz”和“Elizabeth”的数组,alternateNames2将是一个包含“Elizabeth”和“Betty”的数组.
我不想重新发明这个,但我找不到任何这种结构的例子.
更新
感谢那些回复了建议的人.许多人建议使用某些版本的Dictionary<string,IEnumerable<string>>.目前我正在使用这种方法,但它实际上并没有满足要求而不会非常难以维护.每个列表中的每个值都需要能够作为集合中添加到其中的每个其他值的键.
因此,给出以下内容:
data.Add(new string[] {"Elizabeth", "Liz"}
data.Add(new string[] {"Liz", "Betty"}
alternates = data["Betty"];
我希望替补人员现在包含“伊丽莎白”和“利兹”.
看起来我可能只需构建这样的结构以满足我的需求.保持想法即将到来!
布赖恩
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Art of Computer Programming, Volume 2
Knuth, Donald E. / Addison-Wesley Professional / 1997-11-04 / USD 79.99
Finally, after a wait of more than thirty-five years, the first part of Volume 4 is at last ready for publication. Check out the boxed set that brings together Volumes 1 - 4A in one elegant case, and ......一起来看看 《The Art of Computer Programming, Volume 2》 这本书的介绍吧!