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


C# GenericList.ClearList方法代码示例

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


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

示例1: Main

 static void Main()
 {
     try
     {
         GenericList<int> list = new GenericList<int>(5);
         list.Add(1);
         list.Add(2);
         list.Add(1);
         Console.Write("Add : ");
         Console.WriteLine(list.ToString());
         list.Remove(1);
         Console.Write("Remove : ");
         Console.WriteLine(list.ToString());
         list.Insert(3, 555);
         Console.Write("Insert : ");
         Console.WriteLine(list.ToString());
         Console.Write("Clear : ");
         list.ClearList();
         Console.WriteLine(list.ToString());
         Console.WriteLine("Searching element by its value");
         list.Add(1);
         list.Add(2);
         list.Add(1);
         list.Add(2);
         list.Insert(2, 3);
         Console.WriteLine(list.ToString());
         int indexOfElement = list.FindElement(1, 1);
         Console.WriteLine(indexOfElement);
     }
     catch (ArgumentOutOfRangeException exp)
     {
         Console.WriteLine("Error!");
         Console.WriteLine(exp);
     }
 }
开发者ID:naturalna,项目名称:OOPPrinciples,代码行数:35,代码来源:GenericExample.cs

示例2: Main

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

            var attributes = typeof(GenericList<>).GetCustomAttributes(typeof(VersionAttribute), false);
            Console.WriteLine("Version: {0}", ((VersionAttribute)attributes[0]).Version + Environment.NewLine);

            list.AddElement(3);
            list.AddElement(5);
            list.AddElement(12);
            Console.WriteLine("Add elements: {0}", list + Environment.NewLine);

            Console.WriteLine("Get element at index [0] \r\n{0}",
                list[0] + Environment.NewLine);

            list.RemoveElementAtIndex(1);
            Console.WriteLine("Remove element at index [1] \r\n{0}",
                list + Environment.NewLine);

            list.InsertElementAtIndex(2, -3);
            Console.WriteLine("Insert '-3' at index [2] \r\n{0}",
                list + Environment.NewLine);

            Console.WriteLine("Find element '-3' \r\n{0}",
                list.FindElementByValue(-3) + Environment.NewLine);

            Console.WriteLine("STATISTICS \r\nElements count: {0} \r\nMin element: {1} \r\nMax element: {2}",
                list.Count, list.Min(), list.Max() + Environment.NewLine);

            list.ClearList();
            Console.WriteLine("Clear the list \r\nList count: {0}", list.Count);
        }
开发者ID:unbelt,项目名称:SoftUni,代码行数:32,代码来源:GenericListTest.cs

示例3: Main

    public 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.RemoveElemAtIndex(4);

        Console.WriteLine(listTesting);

        listTesting.InsertElemAtIndex(0, 123);

        Console.WriteLine(listTesting);

        Console.WriteLine(listTesting.FindElemByValue(123));

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

        listTesting.ClearList();

        Console.WriteLine(listTesting);
    }
开发者ID:HansS,项目名称:TelerikAcademy-homework,代码行数:29,代码来源:Program.cs

示例4: Main

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

        Console.WriteLine("Adding numbers:");
        list.AddElement(3);
        list.AddElement(5);
        list.AddElement(12);
        Console.WriteLine(list + Environment.NewLine); // Print

        Console.WriteLine("Inserting [-3] at position [2]");
        list.InsertElementAt(2, -3);
        Console.WriteLine(list + Environment.NewLine); // Print

        Console.WriteLine("Removing element at position [1]");
        list.RemoveElementAtIndex(1);
        Console.WriteLine(list + Environment.NewLine);

        Console.WriteLine("Search for number [-3]");
        Console.WriteLine(list.FindElementValue(-3) + Environment.NewLine);

        Console.WriteLine("STATISTICS");
        Console.WriteLine("Elements count: {0}", list.Count);
        Console.WriteLine("Min element: {0}", list.Min());
        Console.WriteLine("Max element: {0}", list.Max());

        list.ClearList();
        Console.WriteLine();
    }
开发者ID:unbelt,项目名称:Telerik,代码行数:29,代码来源:GenericListTest.cs

示例5: Main

        static void Main()
        {
            //GenericList<string> test = new GenericList<string>();
            //test.AddElement("Testing");
            //test.AddElement("string");
            //Console.WriteLine(test.ToString()); //before inserting a new element
            //test.InsertAtIndex(0, "sf");
            //Console.WriteLine(test.ToString());    //after inserting a new element
            //var testAccessByIndex = test.AccessByIndex(1);
            //Console.WriteLine("I am the element at index 1 = {0}", testAccessByIndex);

           GenericList<double> anotherTest = new GenericList<double>();
           anotherTest.AddElement(1);
           anotherTest.AddElement(2);
           anotherTest.AddElement(3);
           anotherTest.AddElement(4);
          
           Console.WriteLine("Numbers = {0}", anotherTest.ToString());
           var minElement = anotherTest.Min();
           Console.WriteLine("MIN element is {0}", minElement);
           var maxElement = anotherTest.Max();
           Console.WriteLine("MAX element is {0}", maxElement);
           Console.WriteLine("Element[1] using indexer = {0}", anotherTest[1]);
           Console.WriteLine("Element AccessByIndex(1) = {0}", anotherTest.AccessByIndex(1));
           anotherTest.RemoveByIndex(1);
           Console.WriteLine("Removed element[1], result = {0}", anotherTest.ToString());
           anotherTest.InsertAtIndex(1, 5);
           Console.WriteLine("Insert 5 at index[1],result = {0}",anotherTest.ToString());
           anotherTest.ClearList();
           Console.WriteLine("Elements ClearList() = {0}", anotherTest.ToString());
           Console.WriteLine("Check if list contains 0: {0}",anotherTest.FindByValue(0));
        }
开发者ID:Alex-Bubblemaster,项目名称:C-Sharp-OOP,代码行数:32,代码来源:TestWithMain.cs

示例6: Main

    public static void Main()
    {
        //testing bellow all of the defined in GenericList
        GenericList<int> listTesting = new GenericList<int>(1);
        listTesting.AddElement(3);
        listTesting.AddElement(2);
        listTesting.AddElement(-100);
        listTesting.AddElement(1);
        listTesting.AddElement(6);

        Console.WriteLine(listTesting);

        listTesting.RemoveElementAtIndex(1);

        Console.WriteLine(listTesting);

        listTesting.InsertElementAtIndex(0, 21);

        Console.WriteLine(listTesting);

        Console.WriteLine(listTesting.FindElementByValue(7));

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

        listTesting.ClearList();

        Console.WriteLine(listTesting);
    }
开发者ID:sbaychev,项目名称:TelerikAcademy,代码行数:29,代码来源:Execute.cs

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

示例8: Main

        static void Main()
        {
            // Craeting list of strings
            GenericList<int> list = new GenericList<int>();

            // Adding elements in the list

            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);

            // Iterate through the elements
            Console.WriteLine("Elements before removing the element at index:{0}", 0);
            //for (int i = 0; i < list.Count; i++)
            //{
            //    Console.WriteLine(list[i]);
            //}
            Console.WriteLine(list);

            // Remove element at position
            list.RemoveAt(0);

            // Iterate through elements
            Console.WriteLine("\nElements after removing the element at index:{0}", 0);
            //for (int i = 0; i < list.Count; i++)
            //{
            //    Console.WriteLine(list[i]);
            //}
            Console.WriteLine(list);

            // Retrieve the min element in the list
            Console.Write("\nMin element in the list: ");
            Console.WriteLine(GenericList<int>.Min<int>(list));

            // Retrieve the max element in the list
            Console.Write("\nMax element in the list: ");
            Console.WriteLine(GenericList<int>.Max<int>(list));

            // Clearing the list
            list.ClearList();
        }
开发者ID:purlantov,项目名称:telerik_academy,代码行数:42,代码来源:GenericListTest.cs

示例9: Main

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

            for (int i = 5; i <= 20; i++)
            {
                testList.Add(i); //Testing method Add
            }

            for (int i = 0; i < testList.Count - 1; i++)
            {
                Console.Write(testList[i]);
            }
            Console.WriteLine();
            Console.Write("Enter search element of GenericList = ");
            int searchTofIndex = int.Parse(Console.ReadLine());
            var resultIndex = testList.IndexOf(searchTofIndex);// testing method indexOf
            Console.WriteLine("Search number is {0} = Index [{1}]", searchTofIndex, resultIndex);

            Console.Write("Enter the number to be inserted = ");

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

            Console.Write("Enter the index to insert = ");

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

            testList.InsertAt(numberOfInsert, indexUser);// testing method InsertAt

            Console.WriteLine("TestList[{0}] = {1}", indexUser, testList[indexUser]);

            Console.WriteLine(testList); //ToString, Min and Max
            Console.WriteLine("Min: {0}", testList.Min());
            Console.WriteLine("Max: {0}", testList.Max());

            testList.ClearList();//test method clear
            for (int i = 0; i < testList.Capacity; i++)
            {
                Console.Write(testList[i]);
            }
            Console.WriteLine(" Test clear");
        }
开发者ID:zivoroka,项目名称:TelerikAcademy,代码行数:42,代码来源:GenericClassMain.cs

示例10: Main

        static void Main()
        {
            // creating an initial array
            GenericList<int> testArray = new GenericList<int>(4);
            Console.WriteLine("The GenericList has {0} elements", testArray.Count);
            Console.WriteLine("The initial capacity is {0}\n", testArray.Capacity);

            // adding elemnts
            for (int i = 1; i < 5; i++)
            {
                testArray.Add(i * 5);
            }
            Console.WriteLine("Now in the GenericList you have {0} elements ", testArray.Count);
            Console.WriteLine("The object at position 1 is {0}\n", testArray[1]);

            // test To.String() method
            Console.WriteLine("ToString {0}\n", testArray);

            // test InsertAt method and FindElementIndex method
            var insertInt = 30;
            testArray.InsertAt(1, insertInt);

            Console.WriteLine("Capacity after AutoGrow is {0}", testArray.Capacity);
            Console.WriteLine("You can find {0} at index {1}"
                , insertInt, testArray.FindElementIndex(insertInt));
            Console.WriteLine("ToString {0}\n", testArray);

            // test RemoveAt method
            testArray.RemoveAt(1);

            Console.WriteLine("Now on position 1 is {0} and the count is {1}", testArray[1], testArray.Count);
            Console.WriteLine("ToString {0}\n", testArray);

            // test Min and Max
            Console.WriteLine("The smallest element is {0} and the biggest is {1}\n"
                , testArray.MinT(), testArray.MaxT());

            // test Clear method
            testArray.ClearList();
            Console.WriteLine("After clear there are {0} elements in the array\n", testArray.Count);
        }
开发者ID:tddold,项目名称:TelerikAcademyHomework,代码行数:41,代码来源:TestGeneric.cs

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

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

        static void Main()
        {
            Console.WriteLine("Hello! This program tests the functionality of the GenericList project. It will run a few tests to determine if the code has been written correctly. Enjoy!");
            Console.WriteLine();
            Console.WriteLine("Creating a new generic list of type GenericList<int> and printing it on the console (empty list)");
            GenericList<int> list = new GenericList<int>();
            Console.WriteLine(list.ToString());
            Console.WriteLine();
            List<int> testList = new List<int>();
            testList.Add(3);

            // Testing "add" method
            Console.WriteLine("Adding 4 elements to the list and printing list after each addition:");
            list.AddElement(5);
            Console.WriteLine(list.ToString());
            list.AddElement(89);
            Console.WriteLine(list.ToString());
            list.AddElement(-15);
            Console.WriteLine(list.ToString());
            list.AddElement(7);
            Console.WriteLine(list.ToString());
            Console.WriteLine();

            // Testing "remove" method
            Console.WriteLine("Removing elements at positions 2, 2 and 0 consecutively and printing list after each removal:");
            list.RemoveElement(2);
            Console.WriteLine(list.ToString());
            list.RemoveElement(2);
            Console.WriteLine(list.ToString());
            list.RemoveElement(0);
            Console.WriteLine(list.ToString());
            Console.WriteLine("Press any key to continue testing...");
            Console.ReadKey();
            Console.WriteLine();
            Console.WriteLine("Adding a new element and prinitng the list:");
            list.AddElement(33);
            Console.WriteLine(list.ToString());
            Console.WriteLine();

            // Testing "insert" method
            Console.WriteLine("Inserting '3' at position 1:");
            list.InsertElement(1, 3);
            Console.WriteLine(list.ToString());
            Console.WriteLine("Inserting '-4' at position 0:");
            list.InsertElement(0, -4);
            Console.WriteLine(list.ToString());
            Console.WriteLine("Inserting '-16' at position 3:");
            list.InsertElement(3, -16);
            Console.WriteLine(list.ToString());
            Console.WriteLine();

            // Testing class by doing larger amount of operations
            Console.WriteLine("Adding 50 elements to the list and printing it:");
            for (int i = 0; i <= 50; i++)
            {
                list.AddElement(i);
            }
            Console.WriteLine(list.ToString());
            Console.WriteLine();
            Console.WriteLine("Removing 25 elements from the list and printing it:");
            for (int i = 0; i <= 25; i++)
            {
                list.RemoveElement(i);
            }
            Console.WriteLine(list.ToString());
            Console.WriteLine();
            Console.WriteLine("Inserting 15 elements in the list and printing it:");
            for (int i = 0; i <= 15; i++)
            {
                list.InsertElement(i, i + 3);
            }
            Console.WriteLine(list.ToString());
            Console.WriteLine();

            // Testing "search" method
            Console.WriteLine("Trying to find element with value 15:");
            Console.WriteLine("The element has index [{0}]", list.FindElement(15));
            Console.WriteLine();

            // Testing "min" and "max" methods
            Console.WriteLine("Finding the value of the smallest and the biggest elements in the list:");
            Console.WriteLine("The smallest element is {0}", list.Min<int>());
            Console.WriteLine("The biggest element is {0}", list.Max<int>());
            Console.WriteLine();

            // Testing "clear" method
            Console.WriteLine("Clearing the list and printing it on the console:");
            list.ClearList();
            Console.WriteLine(list.ToString());

            // Saying good bye!
            Console.WriteLine("The test of the GenericList project has been completed successfully! Have a nice day!");
        }
开发者ID:klimentt,项目名称:Telerik-Academy,代码行数:93,代码来源:TestProgram.cs

示例15: Main

        static void Main(string[] args)
        {
            Console.WriteLine("*********");
            Console.WriteLine("POINT 3D:");
            Console.WriteLine("*********");
            Point3D testPoint1 = new Point3D(5, 6, 7);
            Point3D testPoint2 = new Point3D(6, 7, 9);
            Console.WriteLine("Point1: {0}", testPoint1);
            Console.WriteLine("Point2: {0}", testPoint2);
            Console.WriteLine("Distance: {0}", Distance3D.Distance(testPoint1, testPoint2));
            Console.WriteLine();
            Console.WriteLine("**************");
            Console.WriteLine("GENERIC CLASS:");
            Console.WriteLine("**************");
            GenericList<int> testList = new GenericList<int>(2);
            testList.AddElement(1);
            testList.AddElement(2);
            testList.AddElement(3);
            testList.AddElement(4);
            testList.AddElement(5);
            testList.InsertElementAtGivenPosition(6, 1);
            testList.RemoveElementByIndex(0);
            Console.WriteLine(testList);
            Console.WriteLine("Position of 4: {0}", testList.FindElementByValue(4));
            Console.WriteLine("Max element: {0}", testList.Max());
            Console.WriteLine("Min element: {0}", testList.Min());
            Console.WriteLine("Count: {0}", testList.Count);
            Console.WriteLine("Capacity: {0}", testList.Capacity);
            testList.ClearList();
            testList.AddElement(800);
            Console.WriteLine(testList);
            Console.WriteLine();
            Console.WriteLine("*************");
            Console.WriteLine("MATRIX CLASS:");
            Console.WriteLine("*************");
            Matrix<int> m1 = new Matrix<int>(3, 3);
            Matrix<int> m2 = new Matrix<int>(3, 3);
            // Fill with random numbers
            Random randomGenerator = new Random();
            for (int i = 0; i < m1.Rows; i++)
            {
                for (int j = 0; j < m1.Columns; j++)
                {
                    m1[i, j] = randomGenerator.Next(20);
                    m2[i, j] = randomGenerator.Next(20);
                }
            }
            Console.WriteLine("Matrix 1");
            Console.WriteLine(m1);
            Console.WriteLine("Matrix 2");
            Console.WriteLine(m2);
            Console.WriteLine("Matrix 1 + Matrix 2");
            Console.WriteLine(m1 + m2);
            Console.WriteLine("Matrix 1 - Matrix 2");
            Console.WriteLine(m1 - m2);
            Console.WriteLine("Matrix 1 * Matrix 2");
            Console.WriteLine(m1 * m2);

            Console.WriteLine("******************");
            Console.WriteLine("VERSION ATTRIBUTE:");
            Console.WriteLine("******************");
            Type type = typeof(DefiningClasses);
            object[] allCustomAttributes = type.GetCustomAttributes(false);
            foreach (VersionAttribute attribute in allCustomAttributes)
            {
                Console.WriteLine("Current version is: {0}", attribute.FullVersion);
            }
        }
开发者ID:vot24100,项目名称:Telerik-Academy-Homeworks,代码行数:68,代码来源:DefiningClasses.cs


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