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


C# GenericList.Insert方法代码示例

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


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

示例1: Main

    static void Main()
    {
        GenericList<int> nums = new GenericList<int>() { 1, 2, 5, 7 };
        Console.WriteLine("All elements: " + nums.ToString());

        Console.WriteLine("Num at index 1: " + nums[1]);
        nums.Remove(0);
        Console.WriteLine("Element at index 0 has been removed");
        Console.WriteLine("Num at index 1: " + nums[1]);
        Console.WriteLine("The index of 5 is: " + nums.Find(5));
        Console.WriteLine("Nums contains 7? " + nums.Contains(7));
        for (int index = 0; index < 50; index++)
        {
            nums.Add(9);
            Console.Write("Element added: " + nums[nums.Count - 1]);
            Console.WriteLine(" Count: " + nums.Count + " Capacity: " + nums.Capacity);
        }
        nums.Insert(14, 0);
        nums.Insert(14, 0);
        nums.Insert(14, 0);
        nums.Insert(20, 20);
        Console.WriteLine(nums);
        Console.WriteLine("Min: " + nums.Min());
        Console.WriteLine("Max: " + nums.Max());

        Console.WriteLine("The version of this class is: " + nums.Version());
    }
开发者ID:shnogeorgiev,项目名称:Software-University-Courses,代码行数:27,代码来源:GenericListDemo.cs

示例2: Main

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

            Console.WriteLine();

            myList.Add(123);
            myList.Add(1293);
            myList.Add(11);
            myList.Add(12314);
            myList.Add(111111);

            Console.WriteLine(myList);
            myList.Remove(2);
            myList.Insert(11, 2);
            myList.Insert(666, 0);
            Console.WriteLine(myList);
            Console.WriteLine(myList.Find(11));
            Console.WriteLine(myList.Contains(11121));
            myList.Add(-100);
            Console.WriteLine(myList.Min());

            Type type = myList.GetType();
            object[] allAttributes =
                type.GetCustomAttributes(false)
                .Where(x => x.GetType() == typeof (VersionAttribute))
                .ToArray();

            foreach (VersionAttribute attr in allAttributes)
            {
                Console.WriteLine(attr.Major + "." + attr.Minor);
            }
        }
开发者ID:Vallerious,项目名称:OOP-Homeworks,代码行数:33,代码来源:GenericListTester.cs

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

示例4: Main

        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.Remove(3);
            Console.WriteLine(test);
            Console.WriteLine(test[3]);
            Console.WriteLine(test.IndexOf(121));
            test.Insert(66, 4);
            Console.WriteLine(test);
            test.Insert(66, 4);
            Console.WriteLine(test);
            Console.WriteLine(test.Count);
            Console.WriteLine("Max: " + test.Max());
            Console.WriteLine("Min: " + test.Min());

            Console.WriteLine(test.Contains(121));

            Console.WriteLine();
            var allAttributes = typeof(GenericList<>).GetCustomAttributes(typeof(VersionAttribute), false);
            Console.WriteLine("Version: " + allAttributes[0]);
        }
开发者ID:ScreeM92,项目名称:Software-University,代码行数:32,代码来源:GenericListTest.cs

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

示例6: Main

        static void Main()
        {
            var testArray = new GenericList<int>(10); //we are obliged to pass the initial capacity of the list

            for (int i = 0; i < 10; i++) //adds 10 elements to the array
            {
                testArray.Add(i);
            }

            testArray.Insert(0, 15); //inserts an element with value 15 at index 0 of the list, the list doubles its capacity

            foreach (var item in testArray) //due to the implementation of IEnumerable we are able to print the GenericList with a foreach loop
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();
            testArray.Clear(); //we clear the GenericList and now it holds nothing, Count is reset to 0, Capacity stays the same

            foreach (var item in testArray) //nothing will print as there are no elements present
            {
                Console.WriteLine(item);
            }

            testArray.Add(7);
            testArray.Add(4);
            testArray.Add(5);

            foreach (var item in testArray)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();
            testArray.Insert(2, 61); //inserts 61 at index 2 (where 5 currently is)
            Console.WriteLine();

            foreach (var item in testArray)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();
            testArray.Remove(1); //removes the element at index 1 (4)
            Console.WriteLine();

            foreach (var item in testArray)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("\nIndex of '7' = " + testArray.IndexOf(7)); //returns the index of 7
            Console.WriteLine("\nElement with max value = " + testArray.Max());
            Console.WriteLine("\nElement with min value = " + testArray.Min());

            Console.WriteLine("\nPrint the List: " + testArray.ToString()+"\n");
        }
开发者ID:tokera,项目名称:Telerik-Academy,代码行数:57,代码来源:GenericClasses.cs

示例7: 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);
     test.Insert(10, 10);
     Console.WriteLine(test);
     test.Insert(15, 15);
     Console.WriteLine(test);
 }
开发者ID:NasC0,项目名称:Telerik_Homework,代码行数:13,代码来源:EnsureCapacityTest.cs

示例8: Main

        static void Main()
        {
            //Create new list of strings and show functionality
            GenericList<string> myList = new GenericList<string>(10);
            myList[0] = "My";
            myList[1] = "name";
            myList[2] = "is";
            myList[3] = "Svetlin";
            myList[4] = "Nakov";
            Console.WriteLine(myList);

            myList.Add("I like beer!");
            Console.WriteLine(myList[5]);

            myList.RemoveByIndex(2); // remove 'is'
            Console.WriteLine(myList[2]); //print 'Svetlin'

            myList.Insert(2, "my name");
            Console.WriteLine(myList[2]);

            Console.WriteLine(myList.IndexOfElement("name",0)); // print '1'
            Console.WriteLine();
            Console.WriteLine(myList);
            myList[7] = "aaa";
            myList[8] = "bbb";
            myList[9] = myList.Max(myList[7], myList[8]);
            Console.WriteLine(myList[9]); //print 'bbb'

            //Create new list of strings and show functionality
            GenericList<int> otherList = new GenericList<int>(3);
            Console.WriteLine(otherList[0]);
        }
开发者ID:quela,项目名称:myprojects,代码行数:32,代码来源:Program.cs

示例9: Main

        static void Main(string[] args)
        {
            GenericList<int> test = new GenericList<int>(1);
            test.Add(2);
            test.Add(45);
            test.Add(4);
            test.Add(50);
            test.Add(0);
            test.Add(-1000);

            Console.WriteLine(test);

            test.Remove(4);

            Console.WriteLine(test);

            test.Insert(0, 560);

            Console.WriteLine(test);

            Console.WriteLine(test.Find(123));

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

            test.Clear();

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

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

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

示例12: Main

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

            //var list = new List<int>();

            list.Add(15);
            list.Add(12);
            list.Add(48);
            list.Add(154);

            //list.Insert(4, 77);

            list.Add(13);
            list.Add(44);
            list.Add(78);
            list.Add(99);

            list.Insert(7, 33);

            Console.WriteLine(list);
            Console.WriteLine("Count: " + list.Count);
            Console.WriteLine("Capacity: " + list.Capacity);
            Console.WriteLine("Min: " + list.Min());
            Console.WriteLine("Max: " + list.Max());
        }
开发者ID:SimoPrG,项目名称:TelerikAcademyHomeworks,代码行数:26,代码来源:DefiningClasses.cs

示例13: Main

 static void Main()
 {
     var newList = new GenericList<int>();
     for (int i = 0; i < 5; i++)
     {
         newList.Add(i);
     }
     newList.Remove(3);
     newList.Insert(3, 3);
     Console.WriteLine("For each");
     foreach (var item in newList)
     {
         Console.WriteLine(item);
     }
     Console.WriteLine();
     Console.WriteLine("Index of");
     Console.WriteLine(newList.IndexOf(2));
     Console.WriteLine();
     Console.WriteLine("ToString");
     Console.WriteLine(newList);
     Console.WriteLine();
     Console.WriteLine("Min");
     Console.WriteLine(newList.Min());
     Console.WriteLine();
     Console.WriteLine("Max");
     Console.WriteLine(newList.Max());
     newList.Clear();
     Console.WriteLine("After clear");
     Console.WriteLine(newList);
     Console.WriteLine("Test whatever you want!");
 }
开发者ID:radenkovn,项目名称:Telerik-Homework,代码行数:31,代码来源:GenericClassTest.cs

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

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


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