LINQ-加入多个列表 [英] LINQ - joining multiple lists
本文介绍了LINQ-加入多个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在此处查看了101个Linq示例在该列表中我看不到任何类似内容.如果我只是在这里看不到相关示例,请链接到该示例.
I've looked at the 101 Linq Samples here but I can't see anything like this in that list. If I'm just not seeing a relevant example there, please link to it.
如果我有这3个班级:
class Student { int id; string name }
class Course { int id, string name }
class Enrolment { int studentId; int courseId; }
我将如何使用LINQ来获取学生注册的课程列表? (假设我所有三个类都有一个IList)
How would I use LINQ to get a list of courses a student is enrolled on? (assume I have an IList of all three classes)
推荐答案
怎么样:
IEnumerable<Course> FindCoursesForStudent(Student student)
{
return from enrolment in Enrolments
where enrolment.studentId == student.id
join course in Courses
on enrolment.courseId equals course.id
select course;
}
这篇关于LINQ-加入多个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文