可能重複:
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