本文整理汇总了C#中System.Collections.Specialized.OrderedDictionary.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# OrderedDictionary.CopyTo方法的具体用法?C# OrderedDictionary.CopyTo怎么用?C# OrderedDictionary.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Specialized.OrderedDictionary
的用法示例。
在下文中一共展示了OrderedDictionary.CopyTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Common
private void Common (OrderedDictionary od)
{
Assert.IsNotNull (od.GetEnumerator (), "GetEnumerator");
Assert.AreEqual (0, od.Count, "Count-0");
Assert.IsFalse (od.IsReadOnly, "IsReadOnly");
od.Add ("a", "1");
Assert.AreEqual (1, od.Count, "Count-1");
od["a"] = "11";
Assert.AreEqual ("11", od["a"], "this[string]");
od[0] = "111";
Assert.AreEqual ("111", od[0], "this[int]");
DictionaryEntry[] array = new DictionaryEntry[2];
od.CopyTo (array, 1);
Assert.AreEqual ("111", ((DictionaryEntry)array[1]).Value, "CopyTo");
Assert.AreEqual (1, od.Keys.Count, "Keys");
Assert.AreEqual (1, od.Values.Count, "Values");
Assert.IsTrue (od.Contains ("a"), "Contains(a)");
Assert.IsFalse (od.Contains ("111"), "Contains(111)");
od.Insert (0, "b", "2");
Assert.AreEqual (2, od.Count, "Count-2");
od.Add ("c", "3");
Assert.AreEqual (3, od.Count, "Count-3");
OrderedDictionary ro = od.AsReadOnly ();
od.RemoveAt (2);
Assert.AreEqual (2, od.Count, "Count-4");
Assert.IsFalse (od.Contains ("c"), "Contains(c)");
od.Remove ("b");
Assert.AreEqual (1, od.Count, "Count-5");
Assert.IsFalse (od.Contains ("b"), "Contains(b)");
od.Clear ();
Assert.AreEqual (0, od.Count, "Count-6");
Assert.IsTrue (ro.IsReadOnly, "IsReadOnly-2");
// it's a read-only reference
Assert.AreEqual (0, od.Count, "Count-7");
}
示例2: CopyToTests
public void CopyToTests()
{
var d = new OrderedDictionary();
d["foo"] = "bar";
d[" "] = "asd";
DictionaryEntry[] arr = new DictionaryEntry[3];
Assert.Throws<ArgumentNullException>(() => d.CopyTo(null, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => d.CopyTo(arr, -1));
Assert.Throws<ArgumentException>(() => d.CopyTo(arr, 3));
d.CopyTo(arr, 0);
for (int i = 0; i < 2; i++)
{
Assert.True(d.Contains(arr[i].Key));
Assert.Equal(d[arr[i].Key], arr[i].Value);
}
Assert.NotEqual(arr[0].Key, arr[1].Key);
d.CopyTo(arr, 1);
for (int i = 1; i < 3; i++)
{
Assert.True(d.Contains(arr[i].Key));
Assert.Equal(d[arr[i].Key], arr[i].Value);
}
Assert.NotEqual(arr[1].Key, arr[2].Key);
}