当前位置: 首页>>代码示例>>C#>>正文


C# OrderedDictionary.CopyTo方法代码示例

本文整理汇总了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");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:43,代码来源:OrderedDictionaryTest.cs

示例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);
        }
开发者ID:rajeevkb,项目名称:corefx,代码行数:28,代码来源:OrderedDictionaryTests.cs


注:本文中的System.Collections.Specialized.OrderedDictionary.CopyTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。