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


C# GenericList.RemoveElement方法代码示例

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


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

示例1: Main

 static void Main()
 {
     Console.WriteLine("Hello World.");
     Console.WriteLine("Make new List.");
     GenericList<float> newList = new GenericList<float>(20);
     Console.WriteLine("Add some numbers to the List - 5.3, 6.27, 7.55, 8, 9.09");
     newList.AddElement(5.3f);
     newList.AddElement(6.27f);
     newList.AddElement(7.55f);
     newList.AddElement(8f);
     newList.AddElement(9.09f);
     Console.WriteLine("Print Max element: {0}", newList.Max());
     Console.WriteLine("Print Min element: {0}", newList.Min());
     Console.WriteLine("Add 10 in the biggining.");
     newList.InsertElement(0, 10);
     Console.WriteLine("Print Max element again: {0}", newList.Max());
     Console.WriteLine("Print the List.");
     Console.WriteLine(newList);
     Console.WriteLine("Remove the fourth element.");
     newList.RemoveElement(3);
     Console.WriteLine("Print the List.");
     Console.WriteLine(newList);
     Console.WriteLine("Remove the fourth element.");
     newList.RemoveElement(3);
     Console.WriteLine("Print the List.");
     Console.WriteLine(newList);
     Console.WriteLine("Remove the fourth element.");
     newList.RemoveElement(3);
     Console.WriteLine("Print the List.");
     Console.WriteLine(newList);
     Console.WriteLine("Add 15.56 in the end.");
     newList.InsertElement(3, 15.56f);
     Console.WriteLine("Print the List.");
     Console.WriteLine(newList);
 }
开发者ID:Nikolai-Aleksiev,项目名称:Telerik-Academy-HomeWorks,代码行数:35,代码来源:GenericTest.cs

示例2: Main

        //5. Write a generic class GenericList<T> that keeps a list of
        //elements of some parametric type T. Keep the elements of the list
        //in an array with fixed capacity which is given as parameter in the
        //class constructor. Implement methods for adding element, accessing
        //element by index, removing element by index, inserting element at given
        //position, clearing the list, finding element by its value and ToString().
        //Check all input parameters to avoid accessing elements at invalid positions.
        //6. Implement auto-grow functionality: when the internal array
        //is full, create a new array of double size and move all elements to it.
        //7. Create generic methods Min<T>() and Max<T>() for finding the
        //minimal and maximal element in the  GenericList<T>. You may need to
        //add a generic constraints for the type T.
        static void Main()
        {
            //this class is for testing purposes

            GenericList<int> testList = new GenericList<int>(1);

            //adding some elements
            testList.AddElement(15);
            testList.AddElement(10);
            testList.AddElement(49);
            testList.AddElement(18);

            //testing indexator
            Console.WriteLine(testList[1]);
            testList[1] = 56;
            Console.WriteLine(testList[1]);

            //testing remove by index
            testList.RemoveElement(1);
            Console.WriteLine(testList[1]);
            testList.AddElement(1);
            testList.RemoveElement(testList.Count - 1);

            //inserting by index
            testList.InsertElement(0, 100);

            //testing element counter
            Console.WriteLine("Count: " + testList.Count);

            //find element
            Console.WriteLine(testList.FindElement(49));

            //to string
            Console.WriteLine(testList.ToString());

            testList.AddElement(1);
            testList.AddElement(1);
            testList.AddElement(1);
            testList.AddElement(1);
            testList.AddElement(1);
            testList.AddElement(1);

            //min & max element
            Console.WriteLine(testList.MinElement());
            Console.WriteLine(testList.MaxElement());

            //clearing the list
            testList.Clear();
            Console.WriteLine();
        }
开发者ID:Jarolim,项目名称:HomeWork,代码行数:62,代码来源:Program.cs

示例3: Main

        static void Main()
        {
            GenericList<int> genList = new GenericList<int>();
            Console.WriteLine("Add elements, double capacity when exceeded capacity:");
            genList.AddElement(8);
            genList.AddElement(2);
            Console.WriteLine("{0,-25}List capacity = {1}; Count = {2}", genList, genList.Capacity, genList.Count);
            genList.AddElement(1);
            genList.AddElement(5);
            Console.WriteLine("{0,-25}List capacity = {1}; Count = {2}", genList, genList.Capacity, genList.Count);
            genList.AddElement(9);
            Console.WriteLine("{0,-25}List capacity = {1}; Count = {2}", genList, genList.Capacity, genList.Count);
            Console.WriteLine("Insert element:");
            Console.WriteLine(genList);
            genList.InsertElement(4, 789);
            Console.WriteLine("{0,-25}List capacity = {1}; Count = {2}", genList, genList.Capacity, genList.Count);
            Console.WriteLine("Remove element:");
            genList.RemoveElement(3);
            Console.WriteLine("{0,-25}List capacity = {1}; Count = {2}", genList, genList.Capacity, genList.Count);

            Console.WriteLine("Find min and max elements:");
            Console.WriteLine("\nThe min element in genList is: {0}", genList.Min());
            Console.WriteLine("\nThe max element in genList is: {0}", genList.Max());

            Console.WriteLine("Clear the list:");
            genList.Clear();
            Console.WriteLine("Count = {0}", genList.Count);
            Console.WriteLine("\nThe genList is now cleared.");
        }
开发者ID:studware,项目名称:Ange-Git,代码行数:29,代码来源:GenericClassTest.cs

示例4: Main

        static void Main()
        {
            GenericList<int> test = new GenericList<int>(5);
            test.Add(56);
            test.Add(56);
            test.Add(56);
            test.Add(56);
            test.Add(56);
            test.Add(56);
            GenericList<string> test2 = new GenericList<string>(10);
            test2.Add("asdasda");
            test2.Add("sadasdsd");
            test2.RemoveElement(0);
            Console.WriteLine(test2.ElementByIndex(0));
            test.InsertAt(2, 57);
            Console.WriteLine(test.FindElementByValue(57));
            int t = GenericList<GenericList<string>>.Min<int>(67, 68);
            Console.WriteLine(t);

            //GenericList<int> testList = new GenericList<int>();
            //GenericList<string> testList2 = new GenericList<string>();
            //testList.Add(56);
            //Tuple<int, string> test = new Tuple<int, string>(5, "az");
            //Console.WriteLine(test.Item2);
            //int a = 5;
            //int b = 6;
            //int min = Max<int>(a, b);
            //Console.WriteLine(min);
        }
开发者ID:stefan-petrov,项目名称:TelerikAcademy,代码行数:29,代码来源:Test.cs

示例5: Main

        static void Main(string[] args)
        {
            /*Testing is it working!*/

            GenericList<int> testingGenerics = new GenericList<int>(1);

            // Getting elements:
            testingGenerics.AddElement(1);
            testingGenerics.AddElement(2);
            testingGenerics.AddElement(3);
            testingGenerics.AddElement(4);
            testingGenerics.AddElement(5);
            testingGenerics.AddElement(6);
            Console.WriteLine("The Array is: ");
            Console.WriteLine(testingGenerics);

            // Testing indexator:
            Console.Write("The int on index [3] is: ");
            Console.WriteLine(testingGenerics[3]);
            Console.Write("Changing it to 99: ");
            testingGenerics[3] = 99;
            Console.WriteLine(testingGenerics[3]);

            // Testing remove by index:
            Console.WriteLine();
            Console.WriteLine("Removing element [1]:");
            testingGenerics.RemoveElement(1);
            Console.Write("The new array is: ");
            Console.WriteLine(testingGenerics);

            // Testing the inserting by index:
            Console.WriteLine("Inserting a new element with index[0] = 100");
            testingGenerics.InsertElement(0, 100);
            Console.Write("The new array is: ");
            Console.WriteLine(testingGenerics);

            // Testing element counter:
            Console.WriteLine("The count of elements is: " + testingGenerics.Count);

            // Finding element:
            Console.Write("The element 3 is on index : ");
            Console.WriteLine(testingGenerics.FindElement(3));
            Console.WriteLine();

            //Testing to string
            Console.Write("To String: ");
            Console.WriteLine(testingGenerics.ToString());

            //Testing min & max element
            Console.WriteLine("Min element is: " + testingGenerics.MinElement());
            Console.WriteLine("Max element is: " + testingGenerics.MaxElement());
            Console.WriteLine();

            //clearing the list
            testingGenerics.Clear();
            Console.WriteLine("Cleared array: " + testingGenerics);
        }
开发者ID:Jarolim,项目名称:HomeWork,代码行数:57,代码来源:TestingGenericList.cs

示例6: Main

    static void Main()
    {
        GenericList<int> nums = new GenericList<int>(2);
        // Add elements
        nums.AddElement(5);
        nums.AddElement(10);
        nums.AddElement(1);
        nums.AddElement(8);
        Console.WriteLine("List after adding elements: " + nums + "\n");

        // Remove elements
        nums.RemoveElement(1);
        nums.RemoveElement(2);
        Console.WriteLine("List after removing elements: " + nums + "\n");

        // show element at index
        Console.WriteLine("Element at given index: " + nums.ElementAtIndex(0) + "\n");

        // insert elements at index
        nums.InsertElementAtIndex(10, 50);
        Console.WriteLine(nums);
        nums.InsertElementAtIndex(1, 999);
        Console.WriteLine(nums + "\n");

        // find index of given element
        nums.FindIndex(999);
        nums.FindIndex(444);
        Console.WriteLine();

        // check if list contains element
        Console.WriteLine(nums.Contains(999));
        Console.WriteLine(nums.Contains(444));
        Console.WriteLine();

        // find min element
        Console.WriteLine("Min element is: " + GenericList<int>.Min(10, 7) + "\n");
        // find max element
        Console.WriteLine("Max element is: " + GenericList<string>.Max("Albena", "Ruse"));

        // clear list
        nums.ClearList();
        Console.WriteLine(nums);
    }
开发者ID:ivanovcorp,项目名称:SoftwareUniversity,代码行数:43,代码来源:Test.cs

示例7: Main

 static void Main(string[] args)
 {
     GenericList<int> testList = new GenericList<int>(5);
     testList.AddElement(55);
     testList.AddElement(550);
     testList.AddElement(-55);
     testList.AddElement(564565);
     testList.AddElement(-568);
     testList.AddElement(5500);
     testList.AddElement(5858645);
     testList.AddElement(4444);
     Console.WriteLine(testList.SearchByValue(-568));
     Console.WriteLine(testList.ReadElement(1));
     testList.RemoveElement(1);
     testList.InsertAtPosition(2, -696969);
     Console.WriteLine(testList.Max());
     Console.WriteLine(testList.Min());
 }
开发者ID:nikolovk,项目名称:TelerikAcademy,代码行数:18,代码来源:GenericListProject.cs

示例8: Main

    static void Main()
    {
        GenericList<int> listTesting = new GenericList<int>(1);
        listTesting.AddElement(2);
        listTesting.AddElement(3);
        listTesting.AddElement(4);
        listTesting.AddElement(5);
        listTesting.AddElement(6);
        listTesting.AddElement(-1000);

        Console.WriteLine(listTesting);
        listTesting.RemoveElement(5);
        Console.WriteLine(listTesting);
        listTesting.InsertElement(0,25);
        Console.WriteLine(listTesting);
        Console.WriteLine(listTesting.FindElement(25));
        Console.WriteLine(listTesting.Max());
        Console.WriteLine(listTesting.Min());
        listTesting.ClearList();
        Console.WriteLine(listTesting);
    }
开发者ID:pepakam,项目名称:TelerikAcademy,代码行数:21,代码来源:Program.cs

示例9: Main

 static void Main(string[] args)
 {
     var items = new GenericList<int>(5);
     items.Add(13);
     items.Add(450);
     items.Add(-7);
     items.Add(13);
     items.Add(66);
     items.Add(-17);
     Console.WriteLine("Max element is: "+items.Max());
     Console.WriteLine("Min element is: "+ items.Min());
     Console.WriteLine(items.ToString());
     items.RemoveElement(3);
     Console.WriteLine(items.ToString());
     items.InsertElement(4, 33);
     Console.WriteLine(items.ToString());
     Console.WriteLine("The index of 33 is {0}",items.IndexOf(33));
     items.ClearList();
     items.Add(5);
     Console.WriteLine(items.ToString());
 }
开发者ID:alexizvely,项目名称:Telerik-Academy-2015,代码行数:21,代码来源:RunGeneric.cs

示例10: Main

        static void Main()
        {
            GenericList<int> a = new GenericList<int>(34);

            //Console.WriteLine(a.Capacity);
            a.AddElement(6);
            a.AddElement(7);
            a.AddElement(8);
            //Console.WriteLine(a.Count);

            //Console.WriteLine(a.GetElement(2));

            a.RemoveElement(2);

            for (int i = 0; i < a.Count; i++)
            {
                Console.WriteLine(a.GetElement(i));
            }

            Console.WriteLine();
            a.InsertElement(24, 5);

            for (int i = 0; i < a.Count; i++)
            {
                Console.WriteLine(a.GetElement(i));
            }
            Console.WriteLine();

            //a.Clear();
            //for (int i = 0; i < a.Count; i++)
            //{
            //    Console.WriteLine(a.GetElement(i));
            //}

            Console.WriteLine();

            Console.WriteLine(a.GetIndexOf(7));
        }
开发者ID:DimitarGaydardzhiev,项目名称:TelerikAcademy,代码行数:38,代码来源:MainProgram.cs

示例11: Main

 public static int Main()
 {
     GenericList<int> list = new GenericList<int>(20);
     for (int i = 0; i <= 45; i++)
     {
         list.AddElement(i + 5);
     }
     list.RemoveElement(5);
     Console.Write("Elements: ");
     for (int i = 0; i <= list.Size() - 1; i++)
     {
         Console.Write(list.GetElement((uint)i));
         if (i < list.Size() - 1)
         {
             Console.Write(",");
         }
     }
     Console.WriteLine("\n{0}",list.FindElementByVal(40));
     Console.WriteLine(list.Min());
     Console.WriteLine(list.Max());
     Console.WriteLine(list.ToString());
     return 0;
 }
开发者ID:K-Pavlov,项目名称:Telerik,代码行数:23,代码来源:Test.cs

示例12: Main

 static void Main(string[] args)
 {
     GenericList<int> intList = new GenericList<int>();
     Console.WriteLine(intList);
     intList.AddElement(1);
     intList.AddElement(2);
     intList.AddElement(3);
     intList.AddElement(12);
     Console.WriteLine("number of elements in intList: {0}", intList.Count);
     intList.InsertElement(21, 2);
     Console.WriteLine(intList);
     intList.RemoveElement(2);
     Console.WriteLine(intList);
     Console.WriteLine(intList[2]);
     intList.InsertElement(0, 0);
     intList.AddElement(33);
     Console.WriteLine(intList);
     Console.WriteLine(intList.Min());
     Console.WriteLine(intList.Max());
     intList.ClearList();
     Console.WriteLine(intList);
     Console.WriteLine("number of elements in intList: {0}", intList.Count);
 }
开发者ID:vstoyanov88,项目名称:TelerikAcademy,代码行数:23,代码来源:Program.cs

示例13: Main

        static void Main()
        {
            // Define list
            GenericList<int> testList = new GenericList<int>(1);

            //Test method AddElement and auto grow functionality
            testList.AddElement(1);
            testList.AddElement(2);
            testList.AddElement(3);
            testList.AddElement(4);
            Console.WriteLine(testList);

            // Test method ReadElement
            Console.WriteLine("Element at position 2 is: {0}", testList.ReadElement(2));

            //Test method RemoveElement
            testList.RemoveElement(1);
            Console.WriteLine("After removing an element: {0}", testList);

            //Test method InsertElement
            testList.InsertElement(2, 111);
            Console.WriteLine("After inserting an element: {0}", testList);

            //Test method FindElemenetByValue
            Console.WriteLine("The element is at position: {0}", testList.FindElemenetByValue(111));

            // Test method Min<T>
            Console.WriteLine("Element with minimum value is: {0}",testList.Min());

            // Test method Max<T>
            Console.WriteLine("Element with maximum value is: {0}", testList.Max());

            //Test method ClearList
            testList.ClearList();
            Console.WriteLine("After clearing the list: {0}", testList);
        }
开发者ID:Bunny303,项目名称:TelerikAcademy,代码行数:36,代码来源:Program.cs

示例14: RemoveElementByIndex

        public void RemoveElementByIndex()
        {
            GenericList<string> myList = new GenericList<string>(3);

            myList.AddElement("alpha");
            myList.AddElement("beta");
            myList.AddElement("gama");

            myList.RemoveElement(0);

            var expected = "betagama";
            var actual = "";

            for (int i = 0; i < myList.Len; i++)
            {
                actual += myList[i];
            }

            Assert.AreEqual(expected, actual);
        }
开发者ID:rnikiforova,项目名称:TelerikAcademy,代码行数:20,代码来源:UnitTest1.cs

示例15: Main

        public static void Main()
        {
            // Testing with list of integers
            GenericList<int> listOfIntegers = new GenericList<int>();

            // Adding elements
            listOfIntegers.AddElement(8);
            listOfIntegers.AddElement(9);
            listOfIntegers.AddElement(5);
            listOfIntegers.AddElement(7);

            // Testing the indexator
            Console.Write("The list: ");
            for (int i = 0; i < listOfIntegers.Count; i++)
            {
                Console.Write(listOfIntegers[i]);

                if (i != listOfIntegers.Count - 1)
                {
                    Console.Write(", ");
                }
            }

            Console.WriteLine("\n");
            
            // Inserting elements
            listOfIntegers.InsertElement(2, 10);
            listOfIntegers.InsertElement(4, 11);

            Console.WriteLine("After inserting elements: {0}", listOfIntegers.ToString());
            Console.WriteLine();

           // Removing elements
            listOfIntegers.RemoveElement(1);
            listOfIntegers.RemoveElement(3);

            Console.WriteLine("After removing elements: {0}", listOfIntegers.ToString());
            Console.WriteLine();

            Console.WriteLine("Max: {0}", listOfIntegers.Max<int>());
            Console.WriteLine("Min: {0}", listOfIntegers.Min<int>());

            // Finding element
            Console.WriteLine(listOfIntegers.FindElement(7));

            // Clear the list
            listOfIntegers.ClearGenericList();

            if (listOfIntegers.Count == 0)
            {
                Console.WriteLine("\nThe list is empty");
            }

            Console.WriteLine(new string('-', 50));

            // Testing with list of integers
            GenericList<string> listOfStrings = new GenericList<string>();

            // Adding elements
            listOfStrings.AddElement("Testing");
            listOfStrings.AddElement("some");
            listOfStrings.AddElement("variables");
            listOfStrings.AddElement("with strings");

            // Testing the indexator
            Console.Write("\nThe list: ");
            for (int i = 0; i < listOfStrings.Count; i++)
            {
                Console.Write(listOfStrings[i]);

                if (i != listOfStrings.Count - 1)
                {
                    Console.Write(", ");
                }
            }

            Console.WriteLine("\n");

            // Inserting elements
            listOfStrings.InsertElement(2, "Hi from Penka");
            listOfStrings.InsertElement(4, "LOL");

            Console.WriteLine("After inserting elements: {0}", listOfStrings.ToString());
            Console.WriteLine();

            // Removing elements
            listOfStrings.RemoveElement(1);
            listOfStrings.RemoveElement(3);

            Console.WriteLine("After removing elements: {0}", listOfStrings.ToString());
            Console.WriteLine();

            // Compare strings by the ASCII table
            Console.WriteLine("Max: {0}", listOfStrings.Max<string>());
            Console.WriteLine("Min: {0}", listOfStrings.Min<string>());

            // Finding element
            Console.WriteLine(listOfStrings.FindElement("LOL"));

            // Clear the list
//.........这里部分代码省略.........
开发者ID:g-yonchev,项目名称:Telerik-Academy,代码行数:101,代码来源:GenericListTest.cs


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