我想將一個列表拆分成'n'個子列表。C# - 將列表拆分成n個子列表
我有一份表格教師名單和一份學生名單。每名學生被分配一名錶格老師,每名錶格老師可以有多名學生。表格教師列表是動態的 - 基於表單上的複選框選擇(即:列表中可能有一個,三個,六個等)來填充表格教師列表。
//A method to assign the Selected Form teachers to the Students
private void AssignFormTeachers(List<FormTeacher> formTeacherList, List<Student> studentList)
{
int numFormTeachers = formTeacherList.Count;
//Sort the Students by Course - this ensures cohort identity.
studentList = studentList.OrderBy(Student => Student.CourseID).ToList();
//Split the list according to the number of Form teachers
List<List<Student>> splitStudentList = splitList(numFormTeachers , studentList);
的splitList()
方法就是我試圖名單分成學生列出的清單,但我有一個問題。假設有3位表格教師 - 我似乎無法將列表分成3個子列表,而是最終列出3名學生。
我真的很感謝這個幫助。我已經尋找了一個可能的解決方案,但每次我最終得到大小爲「n」的列表,而不是「n」個列表。如果這個問題之前已經得到解答,請將問題指向該答案的方向。
您是否嘗試過尋找到的GroupBy這個? – Codeman
Please,no camelCase-ing MethodName ...'splitList()'='SplitList()'... See => http://msdn.microsoft.com/en-us/library/4df752aw(v=vs。 71).aspx – Shiva