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


C# Collection.Remove方法代码示例

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


在下文中一共展示了Collection.Remove方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetEnumerator_12

        public void GetEnumerator_12()
        {
            Collection col = new Collection();

            string s1 = "e";
            string s2 = "g";
            string s3 = "a";
            string s4 = "f";

            col.Add(s1,null,null,null);
            col.Add(s2,null,null,null);
            col.Add(s3,null,null,null);

            IEnumerator en = col.GetEnumerator();

            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(s1,en.Current);

            col.Remove(1);

            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(s2,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(s3,en.Current);
            Assert.IsFalse(en.MoveNext());

            col.Add(s4,null,null,null);

            Assert.AreEqual(null,en.Current);
            Assert.IsFalse(en.MoveNext());
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:31,代码来源:CollectionTests.cs

示例2: Exception


//.........这里部分代码省略.........
            try
            {
                // Key "Foot" already exists
                c.Add ("Kickball", "Foot", null, null);
                Assert.Fail ("#E14");
            }
            catch (ArgumentException)
            {
            }

            try
            {
                // Even though Before is object, it's really a string
                c.Add ("Dodgeball", "Dodge", typeof (int), null);
                Assert.Fail ("#E16");
            }
            catch (InvalidCastException)
            {
            }

            try
            {
                // Even though After is object, it's really a string
                c.Add ("Wallyball", "Wally", null, typeof (int));
                Assert.Fail ("#E18");
            }
            catch (InvalidCastException)
            {
            }

            try
            {
                // have to pass a legitimate value to remove
                c.Remove (null);
                Assert.Fail ("#E20");
            }
            catch (ArgumentNullException)
            {
            }

            try
            {
                // no Key "Golf" exists
                c.Remove ("Golf");
                Assert.Fail ("#E22");
            }
            catch (ArgumentException)
            {
            }

            try
            {
                // no Index 10 exists
                c.Remove (10);
                Assert.Fail ("#E24");
            }
            catch (IndexOutOfRangeException)
            {
            }

            try
            {
                IEnumerator e = c.GetEnumerator ();

                // Must MoveNext before Current
                object item = e.Current;
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:67,代码来源:CollectionTests.cs

示例3: GetEnumerator_11

        public void GetEnumerator_11()
        {
            Collection col = new Collection();

            Byte o1 = 1;
            short o2 = 1;
            int o3 = 1;

            col.Add(o1,null,null,null);
            col.Add(o2,null,null,null);
            col.Add(o3,null,null,null);

            IEnumerator en = col.GetEnumerator();

            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o1,en.Current);

            col.Remove(1);

            object o = en.Current;
            Assert.AreEqual (o1, o, "#01");
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:22,代码来源:CollectionTests.cs

示例4: Remove_7

        public void Remove_7()
        {
            // Key cannot be null
            Collection col = new Collection();

            string s1 = "a";
            string s2 = "b";
            string s3 = "c";

            col.Add(s2,"keya",null,null);
            col.Add(s1,"keyb",null,null);
            col.Add(s3,"keyc",null,null);

            col.Remove(null);
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:15,代码来源:CollectionTests.cs

示例5: Count_1

        public void Count_1()
        {
            Collection col = new Collection();

            Assert.AreEqual(0,col.Count);

            col.Add("a",null,null,null);
            Assert.AreEqual(1,col.Count);

            col.Add("b",null,null,null);
            Assert.AreEqual(2,col.Count);

            col.Add("c",null,null,null);
            Assert.AreEqual(3,col.Count);

            col.Add("d",null,null,null);
            Assert.AreEqual(4,col.Count);

            col.Remove(1);
            col.Remove(1);

            Assert.AreEqual(2,col.Count);

            col.Remove(1);
            col.Remove(1);

            Assert.AreEqual(0,col.Count);
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:28,代码来源:CollectionTests.cs

示例6: Remove_5

        public void Remove_5()
        {
            // Collection index must be in the range 1 to the size of the collection.
            Collection col = new Collection();

            string s1 = "a";
            string s2 = "b";
            string s3 = "c";

            col.Add(s2,"keya",null,null);
            col.Add(s1,"keyb",null,null);
            col.Add(s3,"keyc",null,null);

            col.Remove(4);
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:15,代码来源:CollectionTests.cs

示例7: Remove_6

        public void Remove_6()
        {
            // Argument 'Key' is not a valid value.
            Collection col = new Collection();

            string s1 = "a";
            string s2 = "b";
            string s3 = "c";

            col.Add(s2,"keya",null,null);
            col.Add(s1,"keyb",null,null);
            col.Add(s3,"keyc",null,null);

            col.Remove("keyd");
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:15,代码来源:CollectionTests.cs

示例8: Remove_1

        public void Remove_1()
        {
            Collection col = new Collection();

            string s1 = "a";
            string s2 = "b";
            string s3 = "c";

            col.Add(s2,null,null,null);
            col.Add(s1,null,null,null);
            col.Add(s3,null,null,null);
            col.Add(s2 + s1,null,null,null);
            col.Add(s1 + s1,null,null,null);
            col.Add(s3 + s1,null,null,null);

            col.Remove(1);

            Assert.AreEqual(5,col.Count);
            Assert.AreEqual("a",col[1]);
            Assert.AreEqual("c",col[2]);
            Assert.AreEqual("ba",col[3]);
            Assert.AreEqual("aa",col[4]);
            Assert.AreEqual("ca",col[5]);

            col.Remove(3);

            Assert.AreEqual(4,col.Count);
            Assert.AreEqual("a",col[1]);
            Assert.AreEqual("c",col[2]);
            Assert.AreEqual("aa",col[3]);
            Assert.AreEqual("ca",col[4]);

            col.Remove(4);

            Assert.AreEqual(3,col.Count);
            Assert.AreEqual("a",col[1]);
            Assert.AreEqual("c",col[2]);
            Assert.AreEqual("aa",col[3]);

            col.Remove(2);

            Assert.AreEqual(2,col.Count);
            Assert.AreEqual("a",col[1]);
            Assert.AreEqual("aa",col[2]);

            col.Remove(1);

            Assert.AreEqual(1,col.Count);
            Assert.AreEqual("aa",col[1]);

            col.Remove(1);

            Assert.AreEqual(0,col.Count);
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:54,代码来源:CollectionTests.cs

示例9: Remove_2

        public void Remove_2()
        {
            Collection col = new Collection();

            string s1 = "a";
            string s2 = "b";
            string s3 = "c";

            col.Add(s2,"keya",null,null);
            col.Add(s1,"keyb",null,null);
            col.Add(s3,"keyc",null,null);
            col.Add(s2 + s1,"keyd",null,null);
            col.Add(s1 + s1,"keye",null,null);
            col.Add(s3 + s1,"keyf",null,null);

            col.Remove("keya");

            Assert.AreEqual(5,col.Count);
            Assert.AreEqual("a",col[1]);
            Assert.AreEqual("c",col[2]);
            Assert.AreEqual("ba",col[3]);
            Assert.AreEqual("aa",col[4]);
            Assert.AreEqual("ca",col[5]);

            col.Remove("keyd");

            Assert.AreEqual(4,col.Count);
            Assert.AreEqual("a",col[1]);
            Assert.AreEqual("c",col[2]);
            Assert.AreEqual("aa",col[3]);
            Assert.AreEqual("ca",col[4]);

            col.Remove("keyf");

            Assert.AreEqual(3,col.Count);
            Assert.AreEqual("a",col[1]);
            Assert.AreEqual("c",col[2]);
            Assert.AreEqual("aa",col[3]);

            col.Remove("keyc");

            Assert.AreEqual(2,col.Count);
            Assert.AreEqual("a",col[1]);
            Assert.AreEqual("aa",col[2]);

            col.Remove("keyb");

            Assert.AreEqual(1,col.Count);
            Assert.AreEqual("aa",col[1]);

            col.Remove("keye");

            Assert.AreEqual(0,col.Count);
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:54,代码来源:CollectionTests.cs

示例10: RemoveNoKey

        public void RemoveNoKey()
        {
            Collection c;

            c = new Collection ();

            c.Add (typeof (int), null, null, null);
            c.Add (typeof (double), null, null, null);
            c.Add (typeof (string), null, null, null);
            c.Add (typeof (object), null, null, null);

            Assert.AreEqual (4, c.Count, "#RNK01");

            c.Remove (3);

            Assert.AreEqual (3, c.Count, "#RNK02");

            // Collection class is 1-based
            Assert.AreEqual (typeof (object), c[3], "#RNK03");

            c.Remove (1);

            Assert.AreEqual (2, c.Count, "#RNK04");
            Assert.AreEqual (typeof (double), c[1], "#RNK05");
            Assert.AreEqual (typeof (object), c[2], "#RNK06");

            c.Remove (2);

            Assert.AreEqual (1, c.Count, "#RNK07");
            Assert.AreEqual (typeof (double), c[1], "#RNK08");

            c.Remove (1);

            Assert.AreEqual (0, c.Count, "#RNK09");
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:35,代码来源:CollectionTests.cs

示例11: RemoveKey

        public void RemoveKey()
        {
            Collection c;

            c = new Collection ();

            c.Add ("Baseball", "Base", null, null);
            c.Add ("Football", "Foot", null, null);
            c.Add ("Basketball", "Basket", null, null);
            c.Add ("Volleyball", "Volley", null, null);

            Assert.AreEqual (4, c.Count, "#RK01");

            c.Remove ("Foot");

            Assert.AreEqual (3, c.Count, "#RK02");
            Assert.AreEqual ("Basketball", c["Basket"], "#RK03");

            // Collection class is 1-based
            Assert.AreEqual ("Volleyball", c[3], "#RK04");

            c.Remove ("Base");

            Assert.AreEqual (2, c.Count, "#RK05");
            Assert.AreEqual ("Basketball", c[1], "#RK06");
            Assert.AreEqual ("Volleyball", c["Volley"], "#RK07");

            c.Remove (2);

            Assert.AreEqual (1, c.Count, "#RK08");
            Assert.AreEqual ("Basketball", c[1], "#RK09");
            Assert.AreEqual ("Basketball", c["Basket"], "#RK10");

            c.Remove (1);

            Assert.AreEqual (0, c.Count, "#RK11");
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:37,代码来源:CollectionTests.cs

示例12: GetEnumerator_8

        public void GetEnumerator_8()
        {
            Collection col = new Collection();

            Byte o1 = 1;
            short o2 = 1;
            int o3 = 1;

            col.Add(o1,null,null,null);
            col.Add(o2,null,null,null);
            col.Add(o3,null,null,null);

            IEnumerator en = col.GetEnumerator();

            en.MoveNext();

            col.Remove(3);
            col.Remove(2);

            Assert.AreEqual(o1,en.Current);
            Assert.IsFalse(en.MoveNext());
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:22,代码来源:CollectionTests.cs

示例13: GetEnumerator_7

        public void GetEnumerator_7()
        {
            Collection col = new Collection();

            Byte o1 = 1;
            short o2 = 1;
            int o3 = 1;

            col.Add(o1,null,null,null);
            col.Add(o2,null,null,null);
            col.Add(o3,null,null,null);

            IEnumerator en = col.GetEnumerator();

            en.MoveNext();

            col.Remove(1);

            object o = en.Current;
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:20,代码来源:CollectionTests.cs

示例14: SortCollection

		private void SortCollection(Collection col, string psSortPropertyName, bool pbAscending, string psKeyPropertyName = "")
		{
			object obj = null;
			int i = 0;
			int j = 0;
			int iMinMaxIndex = 0;
			object vMinMax = null;
			object vValue = null;
			bool bSortCondition = false;
			bool bUseKey = false;
			string sKey = null;

			bUseKey = (!string.IsNullOrEmpty(psKeyPropertyName));

			for (i = 1; i <= col.Count - 1; i++) {
				obj = col[i];
				vMinMax = Interaction.CallByName(obj, psSortPropertyName, Constants.vbGet);
				iMinMaxIndex = i;

				for (j = i + 1; j <= col.Count; j++) {
					obj = col[j];
					vValue = Interaction.CallByName(obj, psSortPropertyName, Constants.vbGet);

					if ((pbAscending)) {
						bSortCondition = (Convert.ToSingle(vValue) < Convert.ToSingle(vMinMax));
					} else {
						bSortCondition = (Convert.ToSingle(vValue) > Convert.ToSingle(vMinMax));
					}

					if ((bSortCondition)) {
						vMinMax = vValue;
						iMinMaxIndex = j;
					}

					obj = null;
				}

				if ((iMinMaxIndex != i)) {
					obj = col[iMinMaxIndex];

					col.Remove(iMinMaxIndex);
					if ((bUseKey)) {
						sKey = Convert.ToString(Interaction.CallByName(obj, psKeyPropertyName, Constants.vbGet));
						col.Add(obj, sKey, i);
					} else {
						col.Add(obj, "", i);
					}

					obj = null;
				}

				obj = null;
			}

		}
开发者ID:mlnlover11,项目名称:IExtendFramework,代码行数:55,代码来源:DropdownColorBlender.cs


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