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


C# DynamicArray.Remove方法代码示例

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


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

示例1: RemoveTest

 public void RemoveTest()
 {
     int[] A = new int[] { 1, 2, 3, 4 };
     DynamicArray<int> testArr = new DynamicArray<int>(A);
     testArr.Remove(2);
     bool testBool = testArr.Remove(10);
     Assert.AreEqual(testArr[1], 3);
     Assert.AreEqual(testBool, false);
 }
开发者ID:Laetar,项目名称:Epam,代码行数:9,代码来源:MetodTest.cs

示例2: TestRemoveMethod

        public void TestRemoveMethod()
        {
            int[] arr = new[] { 1, 2, 3, 4, 5 };
            DynamicArray<int> m3 = new DynamicArray<int>(arr);
            var b1 = m3.Capacity;
            var flag1 = m3.Remove(5);
            var a1 = m3.Length;
            var b2 = m3.Capacity;
            Assert.AreEqual(a1, 4);
            Assert.AreEqual(flag1, true);
            Assert.AreEqual(b1, b2);

            var flag2 = m3.Remove(7);
            Assert.AreEqual(flag2, false);
        }
开发者ID:egorbulychev127,项目名称:Repository1,代码行数:15,代码来源:TestRemove.cs

示例3: RandomOperation

 public void RandomOperation()
 {
     var r = new Random();
     const int totalOperations = 10000;
     var target = new DynamicArray<int>();
     for (var i = 0; i < totalOperations; i++)
     {
         int oldCount = target.Count;
         switch (r.Next(3))
         {
             case 0: // Add
                 var newItem = r.Next();
                 target.Add(newItem);
                 Assert.AreEqual(oldCount + 1, target.Count);
                 Assert.AreEqual(newItem, target[oldCount]);
                 break;
             case  1: // Remove by index
                 if(oldCount == 0) goto case 0;
                 var indexToRemove = r.Next(oldCount - 1);
                 target.RemoveAt(indexToRemove);
                 Assert.AreEqual(oldCount - 1, target.Count);
                 break;
             case 2: // Remove by element
                 if (oldCount == 0) goto case 0;
                 var itemToRemove = target[r.Next(oldCount - 1)];
                 target.Remove(itemToRemove);
                 Assert.AreEqual(oldCount - 1, target.Count);
                 break;
         }
     }
 }
开发者ID:jbmercha,项目名称:Dast,代码行数:31,代码来源:DynamicArrayUnitTests.cs

示例4: Main

        static void Main(string[] args)
        {
            var array = new DynamicArray<string>();
            array.Add("Georgi");
            array.Add("Nikolai");
            Console.WriteLine(array.IndexOf("Nikolai"));
            Console.WriteLine(array.Cointains("Kiril"));
            array.Remove("Georgi");
            array.InsertAt(1, "Ivan");
            array.Clear();
            Console.WriteLine(array.Capacity);
            Console.WriteLine(array.Count);

            array.Add("Stefan");
            array.Add("Krum");
            var arr = array.ToArray();
            Console.WriteLine();
            foreach (var item in array)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine();

            foreach (var item in arr)
            {
                Console.WriteLine(item);
            }
        }
开发者ID:Redsart,项目名称:Hack-Bulgaria,代码行数:28,代码来源:Program.cs

示例5: Main

 public static void Main()
 {
     DynamicArray<string> arrey = new DynamicArray<string>();
     arrey.Add("Pesho");
     arrey.Add("Gosho");
     Console.WriteLine(arrey.IndexOf("Pesho"));
     Console.WriteLine(arrey.Contains("Gosho"));
     Console.WriteLine(arrey.Contains("Ivan"));
     arrey.Remove("Pesho");
     arrey.InsertAt(1, "Pesho");
     arrey.Clear();
     Console.WriteLine(arrey.Capacity);
     Console.WriteLine(arrey.Count);
     arrey.Add("Ivo");
     arrey[0] = "Gosho";
     var newArrey = arrey.ToArray();
     Console.WriteLine();
     foreach (var item in arrey)
     {
         Console.WriteLine(item);
     }
     Console.WriteLine();
     foreach (var item in newArrey)
     {
         Console.WriteLine(item);
     }
 }
开发者ID:iMitaka,项目名称:HackBulgaria,代码行数:27,代码来源:ProgramMain.cs

示例6: TestMethod1

        public void TestMethod1()
        {
            try
            {
                DynamicArray<int> m1 = new DynamicArray<int>();
                DynamicArray<int> m2 = new DynamicArray<int>(9);

                int[] arr = new[] { 1, 2, 3, 4, 5 };
                DynamicArray<int> m3 = new DynamicArray<int>(arr);

                var a = m3.Length;
                Assert.AreEqual(a, 5);
                var b = m3.Capacity;
                Assert.AreEqual(b, 5);

                m3.Add(6);
                var a1 = m3.Length;
                Assert.AreEqual(a1, 6);
                var b1 = m3.Capacity;
                Assert.AreEqual(b1, 10);

                int[] arr1 = new[] { 7, 8, 9, 10, 11, 12 };
                m3.AddRange(arr1);
                var a3 = m3.Length;
                Assert.AreEqual(a3, 12);
                var b3 = m3.Capacity;
                Assert.AreEqual(b3, 20);

                var flag1 = m3.Remove(7);
                var a4 = m3.Length;
                Assert.AreEqual(a4, 11);
                Assert.AreEqual(flag1, true);

                //m3.Insert(26,14); //Попытка вставить вне границ массива
                m3.Insert(6, 7);
                var b4 = m3[6];
                Assert.AreEqual(b4, 7);

                int k = 1;
                foreach (var elem in m3)
                {
                    var a5 = elem;
                    Assert.AreEqual(a5, k);
                    k++;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Assert.AreEqual(0, 1);

            }
        }
开发者ID:Bulat15,项目名称:repository2,代码行数:53,代码来源:UnitTest1.cs

示例7: Main

   static void Main(string[] args)
   {
       DynamicArray<string> test = new DynamicArray<string>();
     //  test.Add("a");
    //   test.Add("b");
     //  test.Add("b");
       test.Add("c");
       test.Add("a");
   //    test.Add("b");
   //    test.Add("b");
       test.Add("c");
    //   test.Remove("b");
    //   test.Remove("b");
   //    test.Remove("b");
       test.Remove("b");
       test.Remove("a");
 
       Console.WriteLine(test[1]);
       test[1] = "fuck you";
       Console.WriteLine(test[1]);
   }
开发者ID:ivanov961,项目名称:HackBulgaria,代码行数:21,代码来源:Program.cs

示例8: TestMethod1

        public void TestMethod1()
        {
            try
            {
                DynamicArray<int> arr1 = new DynamicArray<int>();
                DynamicArray<int> arr2 = new DynamicArray<int>(20);

                int[] arr3 = new[] { 1, 2, 3, 4, 5 };
                DynamicArray<int> arr4 = new DynamicArray<int>(arr3);

                var a = arr4.Length;
                Assert.AreEqual(a, 5);
                var b = arr4.Capacity;
                Assert.AreEqual(b, 5);

                arr4.Add(6);
                var a1 = arr4.Length;
                Assert.AreEqual(a1, 6);
                var b1 = arr4.Capacity;
                Assert.AreEqual(b1, 10);

                int[] arr31 = new[] { 7, 8, 9, 10, 11, 12 };
                arr4.AddRange(arr31);
                var a3 = arr4.Length;
                Assert.AreEqual(a3, 12);
                var b3 = arr4.Capacity;
                Assert.AreEqual(b3, 20);

                var flag1 = arr4.Remove(7);
                var a4 = arr4.Length;
                Assert.AreEqual(a4, 11);
                Assert.AreEqual(flag1, true);

                arr4.Insert(6, 7);
                var b4 = arr4[6];
                Assert.AreEqual(b4, 7);

                int k = 1;
                foreach (var elem in arr4)
                {
                    var a5 = elem;
                    Assert.AreEqual(a5, k);
                    k++;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Assert.AreEqual(0, 1);
            }
        }
开发者ID:AlbinaKuptsova,项目名称:Kuptsova_Albina,代码行数:51,代码来源:UnitTest1.cs

示例9: Main

        static void Main(string[] args)
        {
            Console.WriteLine("###      LinkedList tests");

            var list = new LinkedList<string>();
            list.Add("x");
            list.Add("g");
            list.Add("s");

            Console.WriteLine(list.Count); //output: 3

            list.InsertAfter("g", "a");
            list.InsertAt(10, "z");
            list.InsertAt(2, "z");
            list.Remove("z");
            list[1] = "m";

            foreach (string value in list)
            {
                Console.WriteLine(value);
            }
            //output:
            //x
            //m
            //a
            //s

            Console.WriteLine("\n###      DynamicArray tests");

            var dArray = new DynamicArray<string>();
            dArray.Add("x");
            dArray.Add("g");
            dArray.Add("s");

            Console.WriteLine(dArray.Count); //output: 3

            dArray.InsertAt(10, "z");
            dArray.InsertAt(2, "z");
            dArray.Remove("z");
            dArray[1] = "m";

            for (int i = 0; i < dArray.Count; i++)
            {
                Console.WriteLine(dArray[i]);
            }
            //output:
            //x
            //m
            //a
            //s

            Console.WriteLine("\n###      Map tests");

            var map = new Map<int, string>();

            map.Add(1, "a");
            map.Add(2, "a");
            map.Add(3, "s");

            Console.WriteLine(map.Count); //output: 3

            try
            {
                map.Add(2, "v");
            }
            catch (ArgumentException argEx)
            {
                Console.WriteLine(argEx.Message); //exception message
            }

            Console.WriteLine(map.ContainsKey(2)); //output: True
            Console.WriteLine(map.ContainsValue("a")); //output: True
            map.Remove(2);
            Console.WriteLine(map.ContainsKey(2)); //output: False
            Console.WriteLine(map.ContainsValue("a")); //output: True

            Console.WriteLine(map.Count); //output: 2

            Console.WriteLine("\n###      HashMap tests");

            var hashMap = new Map<int, string>();

            hashMap.Add(1, "a");
            hashMap.Add(2, "a");
            hashMap.Add(3, "s");

            Console.WriteLine(hashMap.Count); //output: 3

            try
            {
                hashMap.Add(2, "v");
            }
            catch (ArgumentException argEx)
            {
                Console.WriteLine(argEx.Message); //exception message
            }

            Console.WriteLine(hashMap.ContainsKey(2)); //output: True
            Console.WriteLine(hashMap.ContainsValue("a")); //output: True
            hashMap.Remove(2);
//.........这里部分代码省略.........
开发者ID:dragomirevgeniev,项目名称:HackBulgaria,代码行数:101,代码来源:Program.cs

示例10: RemoveNotexistingElementTest

 public void RemoveNotexistingElementTest()
 {
     DynamicArray<int> Arr = new DynamicArray<int>(2);
     Arr.Add(21);
     Arr.Add(26);
     Assert.AreEqual(Arr.Remove(87), false);
 }
开发者ID:PozdeyevArtyom,项目名称:megarepository,代码行数:7,代码来源:Task03Tests.cs

示例11: RemoveExistingElementTest

 public void RemoveExistingElementTest()
 {
     DynamicArray<int> Arr = new DynamicArray<int>(2);
     Arr.Add(99);
     Arr.Add(90);
     Assert.AreEqual(Arr.Remove(90), true);
     Assert.AreEqual(Arr.Length, 1);
 }
开发者ID:PozdeyevArtyom,项目名称:megarepository,代码行数:8,代码来源:Task03Tests.cs


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