.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);