从集合内部的泛型集合分配给泛型集合+;linq+;C#
我在StudentCollection类中有一个学生的通用集合,每个学生类都有一个SubjectCollection类 我有一个返回StudentCollection的方法。如何直接从StudentCollection获取SubjectCollection 我找到了两种方法--- 第一条路 第二条路 是否有其他方法可以做到这一点,比如一行代码直接从StudentCollection获取StudentSubjectCollection 类似于StudentSubjectCollection studentsubjectColl=GetAllStudentCollection().Select(field=>field…);但这不起作用 谢谢 --维奈从集合内部的泛型集合分配给泛型集合+;linq+;C#,c#,linq,C#,Linq,我在StudentCollection类中有一个学生的通用集合,每个学生类都有一个SubjectCollection类 我有一个返回StudentCollection的方法。如何直接从StudentCollection获取SubjectCollection 我找到了两种方法--- 第一条路 第二条路 是否有其他方法可以做到这一点,比如一行代码直接从StudentCollection获取StudentSubjectCollection 类似于StudentSubjectCollection stu
StudentSubjectCollection studentsubjectCollection = new StudentSubjectCollection();
var studentsColl = GetAllStudentCollection();
foreach (var subject in studentsColl )
{
studentsubjectCollection = subject.StudentSubjectCollection;
}
StudentSubjectCollection studentsubjectCollection = new StudentSubjectCollection();
StudentCollection studentColl = GetAllStudentCollection();
foreach (MessageModule messageModule in messageModuleCollection)
{
studentsubjectCollection.AddRange(messageModule.MessageModuleReplyCollection);
}
var students = GetAllStudentCollection();
var subjects = students.SelectMany(stu=>stu.StudentSubjectCollection);