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


C# GenericList.Clear方法代码示例

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


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

示例1: Main

        public static void Main()
        {
            GenericList<int> test1 = new GenericList<int>(3);
            GenericList<string> test2 = new GenericList<string>(3);
            GenericList<byte> test3 = new GenericList<byte>(3);
            Console.WriteLine("Testing adding");
            test1.Add(2);
            test1.Add(3);
            Console.WriteLine("Testing indexing");
            Console.WriteLine(test1[0]);
            Console.WriteLine(test1[1]);
            Console.WriteLine(test1[0] + test1[1]);
            Console.WriteLine("Testing clear");
            test1.Clear();
            //Console.WriteLine(test1[0]); // this will produce error
            test1.Add(1);
            Console.WriteLine(test1[0]);
            //Console.WriteLine(test1[1]); // this will produce error
            Console.WriteLine("Testing Remove At");
            test1.Add(2);
            test1.Add(3);

            Console.WriteLine(test1[1]);

            test1.RemoveAt(1);
            test1.Add(7);
            Console.WriteLine(test1[1]);

            Console.WriteLine("testing InsertAt");
            test1.Clear();
            test1.Add(1);
            test1.Add(2);
            test1.Add(3);
            test1.Add(4);
            test1.InsertAt(9, 2);
            Console.WriteLine(test1[1]);
            Console.WriteLine(test1[2]);
            Console.WriteLine(test1[3]);

            Console.WriteLine("testing Find");
            Console.WriteLine(test1.Find(0));
            Console.WriteLine(test1.Find(9));
            Console.WriteLine(test1.Find(4));

            Console.WriteLine("testing To String");
            Console.WriteLine(test1);

            Console.WriteLine("Testing min and max");
            Console.WriteLine(test1.Min());
            Console.WriteLine(test1.Max());

            test2.Add("asd");
            test2.Add("angry");
            test2.Add("angraer");
            Console.WriteLine(test2.Min());
            Console.WriteLine(test2.Max());
        }
开发者ID:purlantov,项目名称:TelerikAcademy-4,代码行数:57,代码来源:Testing.cs

示例2: 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

示例3: Main

        static void Main()
        {
            GenericList<int> numbers = new GenericList<int>()
            {
                0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
            };
            Console.WriteLine("Creating a GenericList with the numbers from 1 to 20 \n {0} \n", numbers);

            numbers.Remove(19);
            Console.WriteLine("Removing the 19th element \n {0} \n", numbers);

            numbers.Add(100);
            Console.WriteLine("Adding an element to the end of the GenericList \n {0} \n", numbers);

            numbers.Insert(30, 10);
            Console.WriteLine("Inserting an element on the 10th position \n {0} \n", numbers);

            numbers[3] = 9;
            Console.WriteLine("Changing the value of the 3rd index number \n {0} \n", numbers);

            Console.WriteLine("Trying to find number 4 \n Number Found: {0}, Found At: {1} \n", numbers.Contains(4), numbers.Find(4));
            Console.WriteLine("Trying to find number 80 \n Number Found: {0}, Found At: {1} \n", numbers.Contains(80), numbers.Find(80));
            Console.WriteLine("Min element: {0}, Max element: {1} \n", numbers.Min(), numbers.Max());

            numbers.Clear();
            Console.WriteLine("Cleared GenericList: \n {0} \n", numbers);

            Type type = typeof(GenericList<>);
            VersionAttribute attribute = (VersionAttribute)type.GetCustomAttributes(false).LastOrDefault();
            Console.WriteLine("Version: " + attribute.Version);
        }
开发者ID:Bare7a,项目名称:Software-University,代码行数:31,代码来源:Program.cs

示例4: Main

 static void Main()
 {
     GenericList<int> test = new GenericList<int>(10);
     for (int i = 0; i < test.Length; i++)
     {
         test.Add(i);
     }
     Console.WriteLine(test.ToString());
     test.Remove(9);
     Console.WriteLine(test.ToString());
     test.Insert(9, 9);
     Console.WriteLine(test);
     GenericList<int> newTest = new GenericList<int>(10);
     for (int i = 0; i < newTest.Length - 1; i++)
     {
         newTest.Add(i);
     }
     Console.WriteLine(newTest);
     newTest.Insert(10, 9);
     Console.WriteLine(newTest);
     newTest.Clear();
     Console.WriteLine(newTest);
     Console.WriteLine(test[3]);
     GenericList<string> stringTest = new GenericList<string>(10);
     for (int i = 0; i < stringTest.Length - 2; i++)
     {
         stringTest.Add(i.ToString());
     }
     Console.WriteLine(stringTest);
     stringTest.Add("huehuehueheuhe");
     Console.WriteLine(stringTest);
     stringTest.Insert("Teehee", 9);
     Console.WriteLine(stringTest);
 }
开发者ID:NasC0,项目名称:Telerik_Homework,代码行数:34,代码来源:GenericListTest.cs

示例5: 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

示例6: Main

        public static void Main()
        {
            Console.Title = "Problem 3.	Generic ";

            GenericList<int> numbers = new GenericList<int>();
            numbers.Add(5);
            numbers.Add(50);
            numbers.Add(500);
            numbers.Add(1000);

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

            Console.WriteLine(numbers.GetAtIndex(1));
            numbers.Insert(1, 25);
            Console.WriteLine(numbers.IndexOf(50));
            Console.WriteLine(numbers.Contains(5));
            numbers.Remove(5);
            Console.WriteLine(numbers);
            numbers.Clear();
            Console.WriteLine(numbers);

            Console.WriteLine();
            Console.WriteLine("Problem 4.	Generic List Version");
            System.Reflection.MemberInfo info = typeof(GenericList<>);
            foreach (object attribute in info.GetCustomAttributes(false))
            {
                Console.WriteLine(attribute);
            }
        }
开发者ID:Nezhdetov,项目名称:Software-University,代码行数:30,代码来源:GenericListMain.cs

示例7: Main

    static void Main()
    {
        var intList = new GenericList<int>();

        intList.Add(1);
        intList.Add(2);
        intList.Add(3);
        intList.Add(4);
        intList.Add(5);
        Console.WriteLine("Number of elements: {0}", intList.Count);
        Console.WriteLine(intList);
        intList[4] = 133;
        Console.WriteLine(intList);

        intList.Remove(2);
        Console.WriteLine(intList);

        intList.Insert(0, 4);
        Console.WriteLine(intList);

        Console.WriteLine(intList.Find(133));

        Console.WriteLine(intList.Contains(4));

        Console.WriteLine("Max = " + intList.Max());
        Console.WriteLine("Min = " + intList.Min());

        intList.Clear();
        Console.WriteLine("Elemets in List: " + intList.Count);

        Type type = typeof(GenericList<>);
        object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), false);
        Console.WriteLine("GenericsList's version is {0}", ((VersionAttribute)allAttributes[0]).Version);
    }
开发者ID:GeorgiLambov,项目名称:SoftwareUniversity,代码行数:34,代码来源:GenericListTest.cs

示例8: Main

        static void Main()
        {
            GenericList<string> glist = new GenericList<string>();
            glist.Add("First");
            glist.Add("Second");
            glist.Add("Third");
            glist.Add("Pesho");
            glist.Add("Gosho");
            glist.Add("Tosho");

            glist.Insert(0, "Purvi Pesho");

            Console.WriteLine(glist);
            Console.WriteLine("Index of \"Second\": {0}", glist.IndexOf("Second"));
            Console.WriteLine("Does contain \"Toshkata\": {0}", glist.Contains("Toshkata"));
            Console.WriteLine("Does contain \"Pesho\": {0}", glist.Contains("Pesho"));

            Console.WriteLine();

            glist.Remove(2);
            glist.Remove(2);

            Console.WriteLine(glist);
            Console.WriteLine("Min Value: {0}", glist.Min());
            Console.WriteLine("Max Value: {0}", glist.Max());

            glist.Clear();

            Console.WriteLine(glist);
        }
开发者ID:hristodobrev,项目名称:Software-University,代码行数:30,代码来源:GenericListManipulation.cs

示例9: 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

示例10: Main

    static void Main()
    {
        var test = new GenericList<int>(2);

        for (int i = 0; i < 25; i++)
        {
            test.Add(i * 4);
        }

        Console.WriteLine(test);

        test.Remove(5);

        Console.WriteLine(test);

        test.Insert(9, 77);
        Console.WriteLine(test);

        Console.WriteLine("ByValue: {0} ", test.FindIndexByValue(77));
        Console.WriteLine("ByIndex: {0}", test[17]);
        Console.WriteLine("Max: {0} ", test.GetMax());
        Console.WriteLine("Min: {0}" , test.GetMin());

        test.Clear();
    }
开发者ID:RuParusheva,项目名称:TelerikAcademy,代码行数:25,代码来源:Test.cs

示例11: Main

 static void Main(string[] args)
 {
     var listtt = new List<int>();
     GenericList<int> myList = new GenericList<int>(10);
     //ADD
     myList.Add(1);
     myList.Add(2);
     myList.Add(3);
     Console.WriteLine(myList.ToString());
     Console.WriteLine("Insert element");
     //INSERT AT GIVEN POSITION
     myList.Insert(3, 50);
     myList.Insert(3, 60);
     Console.WriteLine(myList.ToString());
     Console.WriteLine("Find element:");
     //FIND CERTAINT ELEMENT AT WHAT INDEXES EXISTS
     myList.Find(25);
     Console.WriteLine("Remove element:");
     //REMOVE AT CERTAIN INDEX
     myList.Remove(2);
     Console.WriteLine(myList.ToString());
     Console.WriteLine("Find maximum");
     //FIND MAX
     Console.WriteLine(myList.Max());
     Console.WriteLine("Find minimum");
     //FIND MIN
     Console.WriteLine(myList.Max());
     //CLEAR ALL
     Console.WriteLine("Clear all");
     myList.Clear();
     Console.WriteLine(myList.ToString());
 }
开发者ID:AYankova,项目名称:Telerik-Academy-HW,代码行数:32,代码来源:Test.cs

示例12: 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

示例13: 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

示例14: Main

    static void Main()
    {
        GenericList<int> list = new GenericList<int>(2);
        list.Add(1);
        list.Add(13);
        list.Add(12);

        Console.WriteLine("Generic list contains: {0}",list);

        Console.WriteLine("Second element of the list is {0}", list[2]);

        Console.WriteLine("Smallest element in the list is {0}", list.Min<int>());

        Console.WriteLine("Biggest element in the list is {0}", list.Max<int>());

        Console.Write("Please enter a value to search: ");

        int valueToSearch = int.Parse(Console.ReadLine());

        Console.WriteLine("Position: {0}", list.Find(valueToSearch));

        list.Clear();

        Console.WriteLine("List Cleared -> {0}", list);
    }
开发者ID:vassil,项目名称:CSharp,代码行数:25,代码来源:TestClass.cs

示例15: 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


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