这里是我想要做的。在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的顺序发生变化。 –
实际上我需要的是针对字符串的特定数字。 ,我也想交换这些对,为了我想要的。 你能帮我吗? –