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


C# GenericList.Add方法代码示例

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


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

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

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

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

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

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

示例6: Main

        static void Main(string[] args)
        {
            //Printing  -  Genreic List Version Atribute  - Problem.04
            var result = typeof(GenericList<int>).GetCustomAttributes(true).First();
            Console.WriteLine(result);

            GenericList<Car> cars = new GenericList<Car>();

            Car ferrari = new Car("Ferrari", "F360", 155000);
            cars.Add(ferrari);
            Car alfa = new Car("Alfa", "Spider", 95000);
            cars.Add(alfa);
            Car mercedes = new Car("Mercedes", "AMG SL65", 135000);
            cars.Add(mercedes);
            Car lada=new Car("Lada","1500",2500);

            Console.WriteLine(cars[0]);
            Console.WriteLine(cars[1]);
            Console.WriteLine(cars[2]);
            Console.WriteLine("List size {0}",cars.Size);
            Console.WriteLine("List capacity {0}",cars.Capacity);

            cars.InsertAt(lada, 2);
            Console.WriteLine(cars[2]);
            Console.WriteLine("List size {0}", cars.Size);
            Console.WriteLine(cars.Contains(ferrari));
        }
开发者ID:AdrianDamyanov,项目名称:CSharpOOP,代码行数:27,代码来源:MainClass.cs

示例7: Main

        public static void Main()
        {
            GenericList<int> myIntList = new GenericList<int>(4);
            myIntList.Add(1);
            myIntList.Add(3);
            myIntList.Insert(1, 2);
            Console.WriteLine("My int list: " + myIntList);
            Console.WriteLine("Max is: " + myIntList.Max());
            Console.WriteLine("Min is: " + myIntList.Min());

            Console.WriteLine();

            GenericList<string> myStringList = new GenericList<string>();
            myStringList.Add("Joro");
            myStringList.Add("Ivan");
            myStringList.Add("Barack Obama");

            Console.WriteLine("My string list: " + myStringList);
            Console.WriteLine("Max is: " + myStringList.Max());
            Console.WriteLine("Min is: " + myStringList.Min());

            Console.WriteLine();

            object[] versionAttributes = typeof(GenericList<string>).GetCustomAttributes(false);
            Console.WriteLine("Version is: " + versionAttributes[1]);
        }
开发者ID:Jorka7a13,项目名称:SoftUni_OOP,代码行数:26,代码来源:MainClass.cs

示例8: Main

    static void Main()
    {
        GenericList<int> list = new GenericList<int>(5);
        list.Add(1);
        list.Add(3);
        list.Add(5);
        list.Add(7);
        list.Add(9);
        //Console.WriteLine(list);

        //list.FindElementWithValue(2);
        //list.FindElementWithValue(3);
        //Console.WriteLine();

        //list.RemoveElementAtIndex(4);
        //Console.WriteLine(list);

        //list.InsertElementAtIndex(1, 2);
        //list.InsertElementAtIndex(5, 1);
        //Console.WriteLine(list);

        //list.ClearList();
        //Console.WriteLine(list);

        // Min() and Max() Test
        Console.WriteLine(list.Min<int>());
        Console.WriteLine(list.Max<int>());
    }
开发者ID:GStoykov,项目名称:TelerikAcademyHomeworks,代码行数:28,代码来源:Program.cs

示例9: Main

        public static void 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.
            GenericList<int> testList = new GenericList<int>(3);
            testList.Add(2);
            testList.Add(3);
            testList.Add(4);
            testList.Remove(3);

            //6 Implement auto-grow functionality: when the internal array is full,
            //create a new array of double size and move all elements to it.
            GenericList<char> growList = new GenericList<char>(2);
            testList.Add('a');
            testList.Add('b');
            testList.Add('c');
            testList.Add('d');
            testList.Add('e');

            //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.
            GenericList<int> comearableList = new GenericList<int>();
            comearableList.Add(1);
            comearableList.Add(4);
            comearableList.Add(1321);
            Console.WriteLine("The biggest element in Comearable List is:");
            Console.WriteLine(comearableList.Max());
        }
开发者ID:slop3n,项目名称:TelerikAcademy,代码行数:31,代码来源:TestingMain.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

        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

示例12: Main

        static void Main()
        {
            GenericList<int> listInt = new GenericList<int>();
            GenericList<string> listString = new GenericList<string>(60);

            listInt.Add(5);
            listInt.Add(6);
            listInt.Add(7);
            listInt.Add(8);

            listString.Add("Generic");
            listString.Add("List");
            int takeElement = listInt.ElementAt(0);

            // list.InsertAt(1, 5);
            // list.RemoveAt(0);
            // list.Clean();
            // int index = list.GetIndex(5);
            // int capacity = list.Capacity;
            // int count = list.Count;

            int min = listInt.Min();
            int max = listInt.Max();

            string minString = listString.Min();
            string maxString = listString.Max();

            Console.WriteLine(listInt);

            Console.WriteLine(listString);
        }
开发者ID:jerko0,项目名称:Telerik-Academy,代码行数:31,代码来源:tastFrom5to7.cs

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

示例14: Main

        static void Main()
        {
            GenericList<int> list = new GenericList<int>(3);
            GenericList<string> listNames = new GenericList<string>(2);

            listNames.Add("Pesho");
            listNames.Add("Avan");
            Console.WriteLine(listNames);
            Console.WriteLine(listNames.Min<string>());

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

            //list.RemoveElement(2);
            //list.Clear();
            list.Insert(10, 0);
            list.Add(-3);
            list.Add(13);
            list.Add(3);
            list.TakeElement(1);
            Console.WriteLine(list);

            Console.WriteLine(list.FindElement(10));

            list.FindElement(2);

            Console.WriteLine("Minimal value: " + list.Min<int>());
            Console.WriteLine("Maximal value: " + list.Max<int>());
            Console.WriteLine("Capacity: " + list.Capacity);
            Console.WriteLine("Count: " + list.Count);
        }
开发者ID:ilian-ivanov,项目名称:Telerik-Academy,代码行数:32,代码来源:GenericListTest.cs

示例15: Main

    static void Main()
    {
        GenericList<int> testList = new GenericList<int>();
        int chislo = 231;
        testList.Add(chislo);
        testList.Add(chislo);
        testList.InsertAtPosition(1, 5);
        testList.InsertAtPosition(1, 5);
        testList.Add(chislo + 9);

        int element = testList[0];
        Console.WriteLine(element);

        testList.RemoveAtIndex(3);

        testList.InsertAtPosition(0, 124);

        //testList.Clear();

        testList.FindElementByValue(421);

        testList.ToStringNew();

        int min = testList.Min();
        Console.WriteLine(min);

        int max = testList.Max();
        Console.WriteLine(max);
    }
开发者ID:hristo11111,项目名称:TelerikAcademy-HristoBratanov,代码行数:29,代码来源:Program.cs


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