【发布时间】:2021-10-27 04:57:21
【问题描述】:
假设我有一个要过滤的对象列表:
using System;
using System.Collections.Generic;
using System.Linq;
public class Person
{
public string Name;
public int Age;
public List<int> Attributes;
}
class HelloWorld
{
static void Main()
{
var p1 = new Person();
p1.Name = "john";
p1.Attributes = new List<int> { 1, 2, 3, 6, 9 };
p1.Age = 25;
var p2 = new Person();
p2.Name = "steve";
p2.Attributes = new List<int> { 2, 5, 9, 10 };
p2.Age = 47;
List<Person> people = new List<Person> { p1, p2 };
people.Where(p=>p.Age > 20)
.Where(p=>p.Attributes ?????);
}
}
如何查询属性超过阈值(例如 >10)的 People 对象?似乎我需要第二个查询,但我不知道如何嵌套它们。
【问题讨论】: