可能重复:
如何从字典中获取第 n 个元素?
如果有一个项目Dictionary
总数,Y
并且我们在<N
时需要第一个项目,那么如何实现这一点?N
Y
例子:
Dictionary<int, string> items = new Dictionary<int, string>();
items.add(2, "Bob");
items.add(5, "Joe");
items.add(9, "Eve");
// We have 3 items in the dictionary.
// How to retrieve the second one without knowing the Key?
string item = GetNthItem(items, 2);
怎么写GetNthItem()
?