public class Student
{
public string Name;
}
public class Class
{
public Student[] Students;
}
public class School
{
public Class[] Classes;
}
Schoolから全Studentの名前のリストを作りたい場合
foreachなら
var names = new List<string>();
foreach (var @class in school.Classes)
{
foreach (var student in @class.Students)
{
names.Add(student.Name);
}
}
LINQを使うと
var names = school.Classes
.SelectMany(o => o.Students)
.Select(o => o.Name)
.ToList();