本文整理汇总了C#中OrderedDictionary.GetOrderedPairs方法的典型用法代码示例。如果您正苦于以下问题:C# OrderedDictionary.GetOrderedPairs方法的具体用法?C# OrderedDictionary.GetOrderedPairs怎么用?C# OrderedDictionary.GetOrderedPairs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrderedDictionary
的用法示例。
在下文中一共展示了OrderedDictionary.GetOrderedPairs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ItemEnumeration
public void ItemEnumeration()
{
OrderedDictionary<string, string> dictionary = new OrderedDictionary<string, string>();
List<KeyValuePair<string, string>> tracking = new List<KeyValuePair<string, string>>();
KeyValuePair<string, string> one = new KeyValuePair<string, string>("1", "one");
KeyValuePair<string, string> two = new KeyValuePair<string, string>("2", "two");
int i = 0;
{ // round 1
dictionary.Add(one);
dictionary.Insert(0, two);
// test implicit pairs order
foreach (KeyValuePair<string, string> item in dictionary)
{
switch (i)
{
case 0:
Assert.AreEqual("2", dictionary[i].Key);
break;
case 1:
Assert.AreEqual("1", dictionary[i].Key);
break;
default:
Assert.Fail("unexpected element");
break;
}
++i;
}
// test explicit pairs order
i = 0;
foreach (KeyValuePair<string, string> item in dictionary.GetOrderedPairs())
{
switch (i)
{
case 0:
Assert.AreEqual("2", dictionary[i].Key);
break;
case 1:
Assert.AreEqual("1", dictionary[i].Key);
break;
default:
Assert.Fail("unexpected element");
break;
}
++i;
}
// test keys order
i = 0;
foreach (string key in dictionary.GetOrderedKeys())
{
switch (i)
{
case 0:
Assert.AreEqual("2", key);
break;
case 1:
Assert.AreEqual("1", key);
break;
default:
Assert.Fail("unexpected element");
break;
}
++i;
}
// test values order
i = 0;
foreach (string key in dictionary.GetOrderedValues())
{
switch (i)
{
case 0:
Assert.AreEqual("two", key);
break;
case 1:
Assert.AreEqual("one", key);
break;
default:
Assert.Fail("unexpected element");
break;
}
++i;
}
}
dictionary.Clear();
Assert.AreEqual(0, dictionary.Count);
i = 0;
{ // round 2
dictionary.Add(one);
dictionary.Add(two);
//.........这里部分代码省略.........