可能重复:
How do I get the nth element from a Dictionary?如何检索字典中的第N个项目?
如果有,总的Y
项Dictionary
,我们需要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()
?
字典都不具备的顺序内置到他们的概念。如果你需要知道这个信息,字典(可能)不是正确的结构使用。 –
dlev
2011-06-17 10:40:32