小编Dec*_*Key的帖子

C#Linq查询帮助删除foreach循环创建更清晰的代码

有没有办法使用linq删除for循环来解决我的问题

我想获得每个学生和该列表中每个主题的主题和总分:

IEnumerable<Student> students = new List<Student> {
    new Student() {Id = 1, Name = "John", Age = 13},
    new Student() {Id = 2, Name = "Mary", Age = 12},
    new Student() {Id = 3, Name = "Anne", Age = 14}
};
Run Code Online (Sandbox Code Playgroud)

我有第二个列表,其中包含所有分数和主题信息:

IEnumerable<StudentScore> studentScores = new List<StudentScore> {
    new StudentScore() {StudentId = 1, Subject = "Maths", Points = 54},
    new StudentScore() {StudentId = 1, Subject = "Maths", Points = 32},
    new StudentScore() {StudentId = 1, Subject = "English", Points …
Run Code Online (Sandbox Code Playgroud)

c# linq

4
推荐指数
1
解决办法
143
查看次数

标签 统计

c# ×1

linq ×1