[英]Applying System.Linq.Expression to a List<T>
我已經有一個預定義的表達式,並且我還有一個列表。 然后如何在該列表上應用和調用表達式? 例如,Linq Expression看起來像這樣:
{Foo[]..Where(o => (o.AuditDateTime > 20/04/2018 00:00:00)).Take(10)}}
我已經有單獨的Foo列表了。
所以我想將表達式基本上應用到Foo列表上,最終結果是使用(o.AuditDateTime > 20/04/2018 00:00:00)
謂詞的列表中排名前10位的項。
// expression can be centralized somewhere
Expression<Func<Foo, bool>> fooFilter = (_) => _.AuditDateTime > new DateTime(2018,4,20);
// from somewhere
Foo[] existingFooList;
var resulting10Foos = existingFooList.Where(fooFilter).Take(10);
Linq 在哪里接受具有Func簽名的代表
Func<Foo, bool> myDelegate = delegate(Foo foo)
{
return foo.AuditDateTime > new DateTime(2018,4,20);
};
然后在哪里使用
existingFooList.Where(myDelegate).Take(10);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.