這裏是我想要做的。在C字典中交換兩個鍵/值對#
有一個字典有54個鍵/值對象。我想要的鍵/值對索引i與在索引j鍵/值對被換...
int i=1; int j=3;
Dictionary<String, int> theDeck = new Dictionary<String, int>();
theDeck.Add("zero", 0);
theDeck.Add("one", 1);
theDeck.Add("two", 2);
theDeck.Add("three", 3);
KeyValuePair<String, int> p1 = theDeck.ElementAt(i);
KeyValuePair<String, int> p2 = theDeck.ElementAt(j);
theDeck.ElementAt(i) = p2; //THIS LINE DOES NOT WORK. WHAT IS ITS ALTERNATIVE
theDeck.ElementAt(j) = p1; //THIS LINE DOES NOT WORK. WHAT IS ITS ALTERNATIVE
我不明白你爲什麼會需要做這個在字典?在字典中排序不是必需的,因爲KEY是如何訪問項目的。訪問字典的任何內容都不會根據KeyValuePairs的順序發生變化。 –
實際上我需要的是針對字符串的特定數字。 ,我也想交換這些對,爲了我想要的。 你能幫我嗎? –