字典中的每个键都有许多整数列表。我需要遍历每个键,并且每次都从列表中获取 n 项并执行此操作,直到我遍历所有列表中的所有项。实施它的最佳方法是什么?我需要实现一些枚举器吗?
编码:
enum ItemType { Type1=1, Type2=2, Type3=3 };
var items = new Dictionary<ItemType, List<int>>();
items[ItemType.Type1] = new List<int> { 1, 2, 3, 4, 5 };
items[ItemType.Type2] = new List<int> { 11, 12, 13, 15 };
items[ItemType.Type3] = new List<int> { 21, 22, 23, 24, 25, 26 };
例如:n=2。
- 第一次迭代返回 1,2,11,12,21,22
- 第二次迭代返回 3,4,13,15,23,24
- 第三次迭代返回 5,25,26
更新:最后我必须按顺序获取这些项目的列表:1,2,11,12,21,22, 3,4,13,15,23,24, 5,25,26