我有一個管理學校的 C# 應用程序,我有一個“課堂”類,其中包含學生列表列表,每個學生都有一個帖子列表...我想要“課堂”類中的一個屬性,它返回此中的所有帖子班級。有沒有 linq 查詢或方法可以做到這一點?internal class Classroom{ private string classId; private List<Student> Students { get; set; } private int Students_nbr { get => Students.Count; } public List<Post> All_Posts { get; set; }//gets all posts from all students}internal class Student{ private int student_id; private string first_name; private string last_name; private List<Post> Posts { get; set; }}internal class Post{ private int post_id; private string title, content;}
1 回答

元芳怎么了
TA貢獻1798條經(jīng)驗 獲得超7個贊
您很可能正在尋找 SelectMany 運算符。
這可能是你的類中的一個方法:
IEnumerable<Post> Posts => StudentsList.SelectMany(student => student.Posts);
- 1 回答
- 0 關注
- 115 瀏覽
添加回答
舉報
0/150
提交
取消