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


C# GenericList.RemoveAt方法代码示例

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


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

示例1: Main

        static void Main()
        {
            string decorationLine = new string('-', 80);
            Console.Write(decorationLine);
            Console.WriteLine("***Creating and clearing lists of some type. Adding, removing, accessing, finding, inserting elements.***");
            Console.Write(decorationLine);

            Console.WriteLine("---Creating an empty list of strings---");
            GenericList<string> list = new GenericList<string>();
            Console.WriteLine("Empty list count: " + list.Count);
            Console.WriteLine("Empty list capacity: " + list.Capacity);

            Console.WriteLine("\n---Adding some elements to the list---");
            for (int count = 0; count < 16; count++)
            {
                list.Add("element " + (count + 1));
            }
            Console.WriteLine("The elements of the list are: " + list.ToString());
            Console.WriteLine("After adding some elements list count: " + list.Count);
            Console.WriteLine("After adding some elements list capacity: " + list.Capacity);

            Console.WriteLine("\n---Printing elements at specific indexes---");
            Console.WriteLine("Printing element with index 5: " + list[5]);
            Console.WriteLine("Printing element with index 0: " + list[0]);

            Console.WriteLine("\n---Removing some elements from the list---");
            list.RemoveAt(5);
            list.RemoveAt(0);
            list.RemoveAt(12);
            Console.WriteLine("After removing elements from the list: " + list.ToString());
            Console.WriteLine("Current list count: " + list.Count);

            Console.WriteLine("\n---Inserting some elements to the list---");
            list.InsertAt("string 5", 5);
            list.InsertAt("appear", list.Count - 1);
            list.InsertAt("string11", list.Count);
            Console.WriteLine("The new list is: " + list.ToString());
            Console.WriteLine("The new list count is: " + list.Count);

            Console.WriteLine("\n---Finding specific elements from the list---");
            Console.WriteLine("The index of 'element 9' is: " + list.Find("element 9"));
            Console.WriteLine("The index of 'element 111' is: " + list.Find("element 111"));

            Console.WriteLine("\n---Finding the maximal and the minimal element in the list---");
            Console.WriteLine("The minimal element in the list is: " + list.Min());
            Console.WriteLine("The maximal element in the list is: " + list.Max());

            Console.WriteLine("\n---Clearing the list---");
            list.Clear();
            Console.WriteLine("List count after clearing the list: " + list.Count);
            Console.WriteLine("List capacity after clearing the list: " + list.Capacity);

            // We cannot use Min() and Max() on "test" because it doesn't implement IComparable<>
            GenericList<Point2D> test = new GenericList<Point2D>();
            test.Add(new Point2D(5, 6));
            test.Add(new Point2D(-2, 1));
            test.Add(new Point2D(-12, -11));
            //test.Min();
            //test.Max()
        }
开发者ID:smihaylovit,项目名称:TelerikAcademy,代码行数:60,代码来源:GenericListTest.cs

示例2: Main

    static void Main()
    {
        try
        {
            GenericList<int> list = new GenericList<int>(2);
            list.Add(10);
            list.Add(5);
            list.Add(4);
            list.Add(34);
            list.Add(124);
            list.Add(488);

            Console.WriteLine("Initial list: " + list.ToString());
            Console.WriteLine("Min: " + list.Min());
            Console.WriteLine("Max: " + list.Max());

            list.RemoveAt(3);

            Console.WriteLine("After removing list[3]: " + list.ToString());

            list.Add(88);

            Console.WriteLine("After adding 88: " + list.ToString());

            list.InsertAt(1, 911);

            Console.WriteLine("After inserting 911 at index 1: " + list.ToString());
            Console.WriteLine("List[4]: " + list[4]);

            list.Clear();
            Console.WriteLine("After clearing list: " + list.ToString());

            list.Add(4);
            list.Add(11);
            list.Add(19);
            Console.WriteLine("New list: " + list.ToString());

            list.RemoveAt(2);
            Console.WriteLine("After removing last element: " + list.ToString());

            Console.WriteLine("List capacity now: " + list.Capacity);
            Console.WriteLine("List size now: " + list.Count);
        }
        catch (IndexOutOfRangeException e)
        {
            Console.WriteLine(e.Message);
        }
    }
开发者ID:Rokata,项目名称:TelerikAcademy,代码行数:48,代码来源:GenericListDemo.cs

示例3: Main

        static void Main()
        {
            GenericList<string> myList = new GenericList<string>();
            Console.WriteLine(myList.Capacity);
            Console.WriteLine(myList.Count);
            Console.WriteLine(myList.Elements);
            myList.Add("1");
            myList.Add("2");

            myList.Add("3");
            myList.Add("4");
            myList.Add("Gosho");
            myList.RemoveAt(3);
            Console.WriteLine(myList.Capacity);
            Console.WriteLine(myList.Count);
            Console.WriteLine(myList.Elements);
            myList.InsertAt(0, "Viki");
            Console.WriteLine(myList.FindIndex("Viki"));
            Console.WriteLine(myList.FindIndex("1"));
            myList.InsertAt(0, "Viki");
            myList.InsertAt(5, "Viktor");
            myList.InsertAt(7, "Viktor");
            myList.Clear();
            myList.Add("Pesho");
        }
开发者ID:bahtev,项目名称:TelerikAcademy,代码行数:25,代码来源:GenericListTest.cs

示例4: Main

        static void Main(string[] args)
        {
            GenericList<int> list = new GenericList<int>(3);
            list.Add(0);
            list.Add(1);
            list.Add(2);

            //Insert at position 2
            list.InsertAt(2,9);
            Console.WriteLine("The 2nd element is:{0}",list[2]);

            //Find the max value
            Console.WriteLine("Max value is:{0}", list.Max());

            //Remove index 2
            list.RemoveAt(2);
            Console.WriteLine(list[2]);
            Console.WriteLine("The 2nd element is:{0}", list[2]);
            //Find the min value
            Console.WriteLine("Min value is:{0}", list.Min());

            //Clear the list
            list.Clear();
            Console.WriteLine("The length of the list after it has been cleared:{0}", list.All.Length);
        }
开发者ID:melliemello,项目名称:TelerikAcademyHomeworks,代码行数:25,代码来源:Program.cs

示例5: Main

        static void Main()
        {
            GenericList<int> list = new GenericList<int>(5);
            StringBuilder result = new StringBuilder();
            list.Add(3);
            list.InsertAt(0, 2);
            list.InsertAt(0, 1);
            result.AppendLine(list.ToString());
            result.AppendLine(String.Format("Count: {0}", list.Count));

            result.AppendLine("--REMOVE AT INDEX 1--");
            list.RemoveAt(1);
            result.AppendLine(list.ToString());
            result.AppendLine(String.Format("Count: {0}", list.Count));

            result.AppendLine("     MIN: " + list.Min());
            result.AppendLine("     MAX: " + list.Max());

            result.AppendLine("-----INDEX OF 3-----");
            result.AppendLine(list.IndexOf(3).ToString());
            result.AppendLine("-----INDEX OF 2-----");
            result.AppendLine(list.IndexOf(2).ToString());

            result.AppendLine("-----CLEAR LIST-----");
            list.Clear();
            result.AppendLine(list.ToString());
            result.AppendLine(String.Format("Count: {0}", list.Count));

            Console.WriteLine(result);
        }
开发者ID:RuzmanovDev,项目名称:TelerikAcademy,代码行数:30,代码来源:Test.cs

示例6: Main

        static void Main()
        {
            GenericList<int> testList = new GenericList<int>(4);

            //testing Add and Capacity
            for (int i = 0; i < 20; i++)
            {
                testList.Add(i + 1);
                Console.WriteLine("Element: {0}, Count: {1} Capacity: {2}",
                    testList[i], testList.Count, testList.Capacity);
            }

            //testing InsertAt and RemoveAt
            for (int i = 0; i < testList.Count; i += 3)
            {
                testList.InsertAt(i, 50);
            }

            for (int i = 0; i < testList.Count; i += 4)
            {
                testList.RemoveAt(i);
            }

            Console.WriteLine(testList);

            //ToString, Min and Max
            Console.WriteLine("Min: {0}", testList.Min());
            Console.WriteLine("Max: {0}", testList.Max());
        }
开发者ID:Moiraines,项目名称:TelerikAcademy,代码行数:29,代码来源:GenericClass.cs

示例7: Main

        static void Main()
        {
            GenericList<int> l = new GenericList<int>(1);

            l.Add(1);
            l.Add(2);
            l.Add(3);
            l.Add(4);
            l.Add(5);
            l.Add(-1);

            Console.WriteLine(l);

            l.RemoveAt(5);

            Console.WriteLine(l);

            l.InsertAt(0, -3);

            Console.WriteLine(l);

            Console.WriteLine(l.IndexOf(-3));

            Console.WriteLine(l.Max());
            Console.WriteLine(l.Min());

            l.Clear();

            Console.WriteLine(l);
        }
开发者ID:neofitov,项目名称:TelerikAcademyHomeworks,代码行数:30,代码来源:Test.cs

示例8: Main

        public static void Main(string[] args)
        {
            var l = new GenericList<int>();

            l.Add(3);
            l.Add(4);
            l.Add(235252532);

            Console.WriteLine(l);

            l.Insert(1, 2);
            Console.WriteLine(l);

            Console.WriteLine(l.Find(4));

            l.RemoveAt(1);
            Console.WriteLine(l);

            l.Add(1);
            l.Add(7);
            l.Add(1);
            l.Add(9);
            l.Add(3);
            l.Add(2);
            l.Add(6);
            l.Add(8);
            Console.WriteLine(l);

            Console.WriteLine(l.Min());
            Console.WriteLine(l.Max());
            l.Clear();
            Console.WriteLine(l);
        }
开发者ID:GenoGenov,项目名称:TelerikAcademyAssignments,代码行数:33,代码来源:GenericTest.cs

示例9: Main

        public static void Main()
        {
            GenericList<int> list = new GenericList<int>();
            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            list.Add(5);
            Console.WriteLine("Making a new list:\n " + list);

            Console.WriteLine("Inserting a number 6 at position 2!");
            list.Insert(2, 6);
            Console.WriteLine(list);

            Console.WriteLine("The position of number 3 is {0}!", list.IndexOf(3));

            Console.WriteLine("Remove an element on position 3.");
            list.RemoveAt(3);
            Console.WriteLine(list);

            Console.WriteLine("The MIN element in the list is {0}", list.Min());
            Console.WriteLine("The MAX element in the list is {0}", list.Max());

            list.Clear();

            Console.WriteLine("The list after list.Clear()! \n" + list);

            //Console.WriteLine(list.Min());
        }
开发者ID:tzigy,项目名称:TelerikAcademy,代码行数:29,代码来源:GenericListTest.cs

示例10: Main

        static void Main()
        {

            GenericList<int> integerList = new GenericList<int>();
            Console.WriteLine(integerList.Capacity); // 16
            Console.WriteLine(integerList.Count); // 0

            integerList.Add(1);
            integerList.Add(2);
            integerList.InsertAt(1, 3);
            Console.WriteLine(integerList.Capacity); // 16
            Console.WriteLine(integerList.Count); // 3
            Console.WriteLine(integerList); // {1, 3, 2}
            Console.WriteLine(integerList.IndexOf(1)); // 0
            Console.WriteLine(integerList.Exists(0)); // False
            Console.WriteLine(integerList.Exists(2)); // True

            integerList.RemoveAt(0);
            Console.WriteLine(integerList); // {3, 2}
            Console.WriteLine(integerList.IndexOf(1)); // -1
            Console.WriteLine(GenericList<int>.Min(integerList)); // 2
            Console.WriteLine(GenericList<int>.Max(integerList)); // 3

            integerList.InsertAt(12, 7);
            Console.WriteLine(integerList.Count); // 13
            Console.WriteLine(integerList); // {3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7}

            System.Reflection.MemberInfo info = typeof(GenericList<>);
            foreach (object attribute in info.GetCustomAttributes(false))
            {
                Console.WriteLine(attribute);
            }


        }
开发者ID:asenAce,项目名称:Software_University_Bulgaria,代码行数:35,代码来源:Start.cs

示例11: Main

        public static void Main()
        {
            Console.WriteLine("> Create new generic list...");
            GenericList<int> list = new GenericList<int>();
            PrintListData(list);

            Console.WriteLine("> Add four items...");
            list = new GenericList<int>(1, 2, 3, 4); // Use the constructor
            PrintListData(list);

            Console.WriteLine("> List is full, add one more item...");
            list.Add(5);
            PrintListData(list);

            Console.WriteLine("> Remove element at index 2...");
            list.RemoveAt(2);
            PrintListData(list);

            Console.WriteLine("> Insert element '3' at index 2...");
            list.InsertAt(3, 2);
            PrintListData(list);

            Console.WriteLine("> Find element '3'...");
            int item = 3;
            int index = list.Find(item);
            Console.WriteLine("Element '{0}' found at index {1}.\n", item, index);

            Console.WriteLine("> Find min and max value...");
            Console.WriteLine("Min: {0}", list.Min());
            Console.WriteLine("Max: {0}\n", list.Max());

            Console.WriteLine(">Clear the list...");
            list.Clear();
            PrintListData(list);
        }
开发者ID:MarKamenov,项目名称:TelerikAcademy,代码行数:35,代码来源:Program.cs

示例12: Main

    public static void Main()
    {
        GenericList<int> test = new GenericList<int>(2);
        test.Add(1);
        test.Add(2);
        test.Add(10);
        test.Add(99);
        test.Add(22);
        test.Add(40);
        test.Add(121);
        test.Add(23);
        Console.WriteLine(test);
        Console.WriteLine(test[3]);
        Console.WriteLine(test.IndexOf(121));
        test.RemoveAt(3);
        Console.WriteLine(test);
        Console.WriteLine(test[3]);
        Console.WriteLine(test.IndexOf(121));
        test.InsertAt(4, 66);
        Console.WriteLine(test);
        Console.WriteLine(test.Count);
        Console.WriteLine("Max: " + test.Max());
        Console.WriteLine("Min: " + test.Min());

        Console.WriteLine();
        //var allAttributes = typeof(GenericList<>).GetCustomAttributes(typeof(VersionAttribute), false);
        //Console.WriteLine("Version: " + allAttributes[0]);
    }
开发者ID:zhanivanov,项目名称:OOP_September_Homeworks,代码行数:28,代码来源:GenericListExample.cs

示例13: Main

        public static void Main()
        {
            GenericList<int> list = new GenericList<int>(2);
            list.Add(1);
            list.Add(2);
            list.Add(69);
            list.Add(97);
            list.Add(64);
            list.Add(28);
            list.Add(67);
            list.Add(123);

            Console.WriteLine("List: " + list);
            Console.WriteLine("List[6]: " + list[6]);
            Console.WriteLine("Index of 67: " + list.IndexOf(67));
            Console.WriteLine();

            list.RemoveAt(6);
            Console.WriteLine("List: " + list);
            Console.WriteLine("List[6]: " + list[6]);
            Console.WriteLine("Index of 67: " + list.IndexOf(67));
            Console.WriteLine();

            list.InsertAt(5, 72);
            Console.WriteLine("List: " + list);
            Console.WriteLine("Count: " + list.Count);
            Console.WriteLine();
            Console.WriteLine("Max: " + list.Max());
            Console.WriteLine("Min: " + list.Min());
            Console.WriteLine();

            var attr = typeof(GenericList<>).GetCustomAttributes(typeof(Version), false);
            Console.WriteLine("Version: " + attr[0]);
        }
开发者ID:StanisInt,项目名称:SoftUniHomeworks,代码行数:34,代码来源:GenericListProgram.cs

示例14: Main

        static void Main()
        {
            GenericList<int> testList = new GenericList<int>(5);
            testList.Add(5);
            testList.Add(45);
            testList.Add(18);
            testList.Add(66);
            testList.Add(22);
            testList.Add(6);
            testList.Add(2);
            testList.Add(9);
            testList.Add(10);

            Console.WriteLine("tstList.Count ->{0}",testList.Count);
            Console.WriteLine(testList.ToString());

            testList.RemoveAt(3);
            Console.WriteLine("After removing an element:");
            Console.WriteLine("tstList.Count ->{0}", testList.Count);
            Console.WriteLine(testList.ToString());

            testList.InsertAt(3, 66);
            Console.WriteLine("After inserting an element:");
            Console.WriteLine("tstList.Count ->{0}", testList.Count);
            Console.WriteLine(testList.ToString());
            Console.WriteLine();
            Console.WriteLine("searching for element:");
            int position=testList.FindByValue(66);
            Console.WriteLine("The element is on position {0}", position);
            position = testList.Min();
            Console.WriteLine("The Min Element in list is {0}",position);
            position = testList.Max();
            Console.WriteLine("The Max Element in list is {0}",position);
        }
开发者ID:kicata,项目名称:OPP,代码行数:34,代码来源:TestGenericListClass.cs

示例15: Main

        static void Main()
        {
            GenericList<int> test = new GenericList<int>();
            GenericList<int> test1 = new GenericList<int>(5);

            for (int i = 0; i < 10; i++)
            {
                test.AddElement(i + 1);
                Console.WriteLine("Element {0,5}    Count {1,5}    Capacity {2,5}",test[i],test.Count,test.Capacity);
            }

            Console.WriteLine();
            for (int i = 0; i < test1.Capacity; i++)
            {
                test1.AddElement(i + 10);
                Console.WriteLine("Element {0,5}    Count {1,5}    Capacity {2,5}", test1[i], test1.Count, test1.Capacity);
            }

            Console.WriteLine();
            test.InsertAt(1, 22);
            Console.WriteLine(test);
            Console.WriteLine("New length: {0}",test.Count);
            Console.WriteLine();
            test1.RemoveAt(2);
            Console.WriteLine(test1);
            Console.WriteLine("New length: {0}",test1.Count);

            Console.WriteLine();
            Console.WriteLine("Min: {0}",test.Min());
            Console.WriteLine("Max: {0}",test.Max());
        }
开发者ID:AYankova,项目名称:CSharp,代码行数:31,代码来源:GenericListTest.cs


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