Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从集合内部的泛型集合分配给泛型集合+;linq+;C#_C#_Linq - Fatal编程技术网

从集合内部的泛型集合分配给泛型集合+;linq+;C#

从集合内部的泛型集合分配给泛型集合+;linq+;C#,c#,linq,C#,Linq,我在StudentCollection类中有一个学生的通用集合,每个学生类都有一个SubjectCollection类 我有一个返回StudentCollection的方法。如何直接从StudentCollection获取SubjectCollection 我找到了两种方法--- 第一条路 第二条路 是否有其他方法可以做到这一点,比如一行代码直接从StudentCollection获取StudentSubjectCollection 类似于StudentSubjectCollection stu

我在StudentCollection类中有一个学生的通用集合,每个学生类都有一个SubjectCollection类

我有一个返回StudentCollection的方法。如何直接从StudentCollection获取SubjectCollection

我找到了两种方法---

第一条路 第二条路 是否有其他方法可以做到这一点,比如一行代码直接从StudentCollection获取StudentSubjectCollection

类似于StudentSubjectCollection studentsubjectColl=GetAllStudentCollection().Select(field=>field…);但这不起作用

谢谢 --维奈

        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);