【发布时间】:2013-12-30 06:00:21
【问题描述】:
我有一个大型 IEnumerable EntityObjects 和一个大型 IEnumerable 字符串,它们是对象的键。
我想获得一个只包含匹配键的对象的新列表。目前我正在通过Contains() 执行此操作 - 但它似乎很慢?
class Foo {
string Key
string Prop1
int Prop2
decimal Prop3
Bar Prop4
Thing Prop5
Stuff Prop6
...more properties
}
IEnumerable<Foo> foos
IEnumerable<string> fooKeys
var matchedFoos = foos.Where(f => fooKeys.Contains(f.Key));
这工作并返回我所期望的,但似乎很慢,我认为必须有更好的方法?我看过一些关于 Intersect 的帖子,但似乎是针对同一类型的枚举的?
信息:
-
foos.Count()约 164,000 -
fooKeys.Count()约 75,000
【问题讨论】:
标签: c# performance linq ienumerable