【发布时间】:2010-08-03 19:04:11
【问题描述】:
这是一个普遍的问题,但这是我正在寻找解决方案的具体案例:
我有一个Dictionary<int, List<string>> 我想应用各种谓词。我想要一种可以处理多个 LINQ 查询的方法,例如:
from x in Dictionary
where x.Value.Contains("Test")
select x.Key
from x in Dictionary
where x.Value.Contains("Test2")
select x.Key
所以我正在寻找这样的方法:
public int GetResult(**WhatGoesHere** filter)
{
return from x in Dictionary.Where(filter)
select x.Key;
}
这样使用:
int result;
result = GetResult(x => x.Value.Contains("Test"));
result = GetResult(x => x.Value.Contains("Test2"));
WhatGoesHere 的正确语法是什么?
【问题讨论】:
-
糟糕,我错过了正确的类型。我删除了我的答案。 Mark Byer 的回答很好。
标签: c# .net linq linq-to-objects predicate