示例一
internal class Program
{
private static void Main(string[] args)
{
List<Teacher> teachers = new List<Teacher>
{
new Teacher("a",new List<Student1>{ new Student1(),new Student1(),new Student1() }),
new Teacher("b",new List<Student1>{ new Student1(),new Student1(),new Student1() }),
new Teacher("c",new List<Student1>{ new Student1(),new Student1(),new Student1() }),
new Teacher("d",new List<Student1>{ new Student1(),new Student1(),new Student1() }),
new Teacher("e",new List<Student1>{ new Student1(),new Student1(),new Student1() }),
new Teacher("f",new List<Student1>{ new Student1(),new Student1(),new Student1() }),
new Teacher("g",new List<Student1>{ new Student1(),new Student1(),new Student1() })
};
IEnumerable<Student1> t1 = teachers.SelectMany(s => s.Students.Where(w => w.Score < ));
t1.ToList().ForEach(f => Console.WriteLine(f));
Console.Read();
}
}
internal class Student1
{
public int Score { get; set; }
public Student1(int score)
{
Score = score;
}
public override string ToString()
{
return $"studen1 : {Score}";
}
}
internal class Teacher
{
public string Name { get; set; }
public List<Student1> Students;
public Teacher(string order, List<Student1> students)
{
Name = order;
Students = students;
}
}
示例二
var query = from left in Enumerable.Range(, )
from right in Enumerable.Range(, left)
select new { left, right };
var result = Enumerable.Range(, ).SelectMany(left => Enumerable.Range(, left), (left, right) => new { left, right });
foreach (var item in result)
{
Console.WriteLine(item);
}