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


C# OrderedDictionary.RemoveAt方法代码示例

本文整理汇总了C#中System.Collections.Specialized.OrderedDictionary.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# OrderedDictionary.RemoveAt方法的具体用法?C# OrderedDictionary.RemoveAt怎么用?C# OrderedDictionary.RemoveAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.Specialized.OrderedDictionary的用法示例。


在下文中一共展示了OrderedDictionary.RemoveAt方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: CountTests

        public void CountTests()
        {
            var d = new OrderedDictionary();
            Assert.Equal(0, d.Count);

            for (int i = 0; i < 1000; i++)
            {
                d.Add(i, i);
                Assert.Equal(i + 1, d.Count);
            }

            for (int i = 0; i < 1000; i++)
            {
                d.Remove(i);
                Assert.Equal(1000 - i - 1, d.Count);
            }

            for (int i = 0; i < 1000; i++)
            {
                d[(object)i] = i;
                Assert.Equal(i + 1, d.Count);
            }

            for (int i = 0; i < 1000; i++)
            {
                d.RemoveAt(0);
                Assert.Equal(1000 - i - 1, d.Count);
            }
        }
开发者ID:rajeevkb,项目名称:corefx,代码行数:29,代码来源:OrderedDictionaryTests.cs

示例3: RemoveAtTests

        public void RemoveAtTests()
        {
            var d = new OrderedDictionary();

            Assert.Throws<ArgumentOutOfRangeException>(() => d.RemoveAt(0));
            Assert.Throws<ArgumentOutOfRangeException>(() => d.RemoveAt(-1));
            Assert.Throws<ArgumentOutOfRangeException>(() => d.RemoveAt(5));

            Assert.Throws<ArgumentNullException>(() => d.Remove(null));

            for (var i = 0; i < 1000; i++)
            {
                d.Add("foo_" + i, "bar_" + i);
            }
            for (var i = 0; i < 1000; i++)
            {
                d.RemoveAt(1000 - i - 1);
                Assert.Equal(1000 - i - 1, d.Count);
            }
            for (var i = 0; i < 1000; i++)
            {
                d.Add("foo_" + i, "bar_" + i);
            }
            for (var i = 0; i < 1000; i++)
            {
                Assert.Equal("bar_" + i, d[0]);
                d.RemoveAt(0);
                Assert.Equal(1000 - i - 1, d.Count);
            }
        }
开发者ID:rajeevkb,项目名称:corefx,代码行数:30,代码来源:OrderedDictionaryTests.cs

示例4: ReadOnly_RemoveAt

		public void ReadOnly_RemoveAt ()
		{
			OrderedDictionary od = new OrderedDictionary ().AsReadOnly ();
			od.RemoveAt (0);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:5,代码来源:OrderedDictionaryTest.cs

示例5: RandomizeDictionary

        private void RandomizeDictionary(ref OrderedDictionary dict)
        {
            OrderedDictionary newDict = new OrderedDictionary();

            int i = 0;
            while (dict.Count > 0)
            {
                object[] keys = new object[dict.Count];
                dict.Keys.CopyTo(keys, 0);
                object[] values = new object[dict.Count];
                dict.Values.CopyTo(values, 0);

                i = rand.Next(0, dict.Count - 1);
                newDict.Add(keys[i], values[i]);
                dict.RemoveAt(i);
            }

            dict = newDict;
        }
开发者ID:RafaelSz,项目名称:Wordpress-Data-Generator,代码行数:19,代码来源:WPData.cs

示例6: AsReadOnly_AttemptingToModifyDictionary_Throws

        public void AsReadOnly_AttemptingToModifyDictionary_Throws()
        {
            OrderedDictionary orderedDictionary = new OrderedDictionary().AsReadOnly();
            Assert.Throws<NotSupportedException>(() => orderedDictionary[0] = "value");
            Assert.Throws<NotSupportedException>(() => orderedDictionary["key"] = "value");
 
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Add("key", "value"));
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Insert(0, "key", "value"));
 
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Remove("key"));
            Assert.Throws<NotSupportedException>(() => orderedDictionary.RemoveAt(0));
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Clear());
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:13,代码来源:OrderedDictionaryTests.cs


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