我有这样的代码:
.Where(o => o.Parents.Contains(name))
上面的代码不起作用,因为
Parents
包含Parent
对象的列表,这些对象又具有属性Name
。我想检查Name
属性,但这是一个列表,所以我该如何检查?因此,当列表中的任何Where
对象的true
属性设置为Parent
时,我都希望Name
是name
。 最佳答案
尝试以下代码片段:
.Where(o => o.Parents.Any(p => p.Name == name))
关于c# - LINQ在哪里过滤列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10541333/