我知道我可以通过这种方式从一个简单的列表中获取最大值和索引
List<Employee> emplist = new List<Employee>()
{
new Employee{Age=15, name = "Tom"},
new Employee{Age=17, name = "Billy"},
new Employee{Age=25, name = "Sam"}
};
int maxvalue = emplist.Select(i => i.Age).Max();
int index = empList.FindIndex(t => t.Age == maxvalue);
但是对于嵌套列表
List<Employee> emplist = new List<Employee>()
{
new Employee{Age=15, name = "Tom", new List<project>
{
ID = 12, name = "Project A",
ID = 11, name = "Project B",
ID = 16, name = "Project C"
}},
new Employee{Age=17, name = "Billy",new List<project>
{
ID = 17, name = "Project D",
ID = 18, name = "Project E",
ID = 10, name = "Project F"
}},
new Employee{Age=25, name = "Sam",new List<project>
{
ID = 22, name = "Project X",
ID = 24, name = "Project Y",
ID = 19, name = "Project Z"
}}
};
我知道如何获取 ID 的最大值,但不知道如何获取它的两个索引。
int maxvalue = emplist.SelectMany(i => i.project).Select(a => a.ID).Max();
最大值为 24。我也想获取两个索引(员工索引 2 和项目索引 1)