我想用FindAll过滤一个列表
如果我写:
.FindAll(
p => p.Field == Value &&
p.otherObjList.Contains(otherObj));没关系,但如果我写
.FindAll(
p => p.Field == Value &&
p.otherObjList.Contains(
q => q.Field1 == Value1 &&
q.Field2 == Value2));我得到C#语法错误消息:未知方法FindAll(?)的..。otherObjList
我不能准确地定义otherObj,因为我只知道两个字段Field1和Field2的值。
我做错了什么?在这种情况下我能做什么?
发布于 2011-05-23 21:39:07
大多数集合类型和LINQ版本的Contains()方法都需要与集合类型相同的参数,而不是lambda。
似乎您只是想检查是否有任何项目符合某些条件。您应该使用Any()方法。
.FindAll(p => p.Field == Value
&& p.otherObjList.Any(q => q.Field1 == Value1 && q.Field2 == Value2))https://stackoverflow.com/questions/6103323
复制相似问题