结合了集合和字典语义的.Net数据结构
.Net 是否有一个开箱即用的通用集合类型,它结合了 Set 和 Dictionary 语义,这样我只存储项目,但也可以通过从每个项目派生的某个键进行快速查找?像这样的东西:
var foos = new KeyedSet<string, Foo>(foo => foo.ID);
foos.Add(new Foo { ID = "X234", Descr = "One foo" });
foos.Add(new Foo { ID = "Q909", Descr = "Another foo" });
Console.WriteLine("Foo Q909 is {0}", foos["Q909"].Descr);
Is there an out-of-the-box generic collection type for .Net that combines Set and Dictionary semantics, such that I only store items, but can also do fast look-ups by some key that is derived from each item? Something like this:
var foos = new KeyedSet<string, Foo>(foo => foo.ID);
foos.Add(new Foo { ID = "X234", Descr = "One foo" });
foos.Add(new Foo { ID = "Q909", Descr = "Another foo" });
Console.WriteLine("Foo Q909 is {0}", foos["Q909"].Descr);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
KeyedCollection
KeyedCollection<TKey, TItem>