我知道我可以用循环来做到这一点(事实上,我现在是,但我正在努力学习/提高我的 Linq 技能,我也希望它能提供更有效的解决方案。所以,这是我的场景:
假设我有以下 3 个列表(我只是在编一个类似的例子,所以请原谅这是愚蠢的):
Dim lstTeachers as New List(of string)
Dim lstStudentsSex as New List(of string)
Dim lstStudentName as New List(of string)
例如,它们如下:
lstTeachers: lstStudentsSex: lstStudentName:
Teacher 1 Male Whatever Name 1
Teacher 2 Female Whatever Name 2
Teacher 1 Female Whatever Name 3
Teacher 1 Female Whatever Name 4
Teacher 2 Male Whatever Name 5
Teacher 3 Male Whatever Name 6
Teacher 3 Female Whatever Name 7
Teacher 1 Male Whatever Name 8
Teacher 1 Female Whatever Name 9
Teacher 2 Male Whatever Name 10
每个列表中的每个条目都与具有相同索引的其他条目匹配 - 基本上就像一个数据表,只是存储在单独的列表中。
现在,假设我想使用以下值创建以下结构:
Dim dictTeacherSexName as New Dictionary(Of String, Dictionary(Of String, List(of String)))
Dict1_Key: Dict1_Value / Dict2_Key: Dict2_Value:
Teacher 1 Male Whatever Name 1
Whatever Name 8
Female Whatever Name 3
Whatever Name 4
Whatever Name 9
Teacher 2 ...
...我希望这能解释我想要完成的事情。
现在,再次,我知道这可能是一个愚蠢的想法,但我也问它,因为我想提高我的 Linq 技能 - 特别是 Group By 和多个 Selects 仍然抓住我,所以请帮忙。
非常感谢!