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


C# GenericList.InsertAt方法代码示例

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


在下文中一共展示了GenericList.InsertAt方法的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()
        {
            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

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

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

示例5: Main

 static void Main()
 {
     GenericList<double> genList = new GenericList<double>(8);
     genList.Add(1.234);
     genList.Add(3.2);
     genList.Add(67.4);
     genList.InsertAt(76.1, 3);
     genList.Add(11.2);
     genList.InsertAt(222.25, 3);
     genList.InsertAt(123.01, 7);
     Console.WriteLine(genList.ToString());
 }
开发者ID:Jarolim,项目名称:AllMyHomeworkForTelerikAcademy,代码行数:12,代码来源:TestGenericList.cs

示例6: Main

 static void Main()
 {
     GenericList<int> array = new GenericList<int>(8);
     array.Add(5);
     array.Add(8);
     array.Add(3);
     array.InsertAt(88, 3);
     array.Add(33);
     array.InsertAt(1337, 3);
     array.InsertAt(1338, 7);
     string result = array.ToString();
 }
开发者ID:Jarolim,项目名称:HomeWork,代码行数:12,代码来源:Program.cs

示例7: Main

 static void Main(string[] args)
 {
     GenericList<int> list = new GenericList<int>(3);
     list.Add(5);
     list.Add(6);
     list.Add(7);
     list.InsertAt(0, 10);
     list.Remove(1);
     list.InsertAt(2, 0);
     Console.WriteLine(list[4]);
     Console.WriteLine(list);
     Console.WriteLine(list.Min());
     Console.WriteLine(list.Max());
 }
开发者ID:kalinnikol,项目名称:TelerikAcademy-1,代码行数:14,代码来源:Program.cs

示例8: Main

        static void Main(string[] args)
        {
            GenericList<int> gl = new GenericList<int>(4); // Set the capacity of the list

            // Add some element
            gl.Add(1);
            gl.Add(2);
            gl.Add(3);
            gl.Add(4);

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(gl); // Show the elements
            Console.WriteLine("Count = {0}", gl.Count); // Show the number of added elements
            Console.WriteLine("Capacity = {0}\n", gl.Capacity); // Show the capacity

            gl.InsertAt(0, -1); // Insert element at given position
            gl.InsertAt(3, 256);

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(gl);
            Console.WriteLine("Count = {0}", gl.Count);
            Console.WriteLine("Capacity = {0}\n", gl.Capacity);

            // Add some elements
            gl.Add(1);
            gl.Add(2);
            gl.Add(3);
            gl.Add(4);

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine(gl);
            Console.WriteLine("Count = {0}", gl.Count);
            Console.WriteLine("Capacity = {0}\n", gl.Capacity);

            // Find element with value 1 starting searching from given position
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Index of element with value 1, starting from index 0 is № = {0}", gl.Find(1));
            Console.WriteLine("Index of element with value 1, starting from index 4 is № = {0}", gl.Find(1, 4));

            Console.WriteLine();

            // Find min and max 
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("List's min value = {0}", gl.Min());
            Console.WriteLine("List's max value = {0}", gl.Max());

            Console.WriteLine();
            Console.ResetColor();
        }
开发者ID:nikolay-radkov,项目名称:Telerik-Academy,代码行数:49,代码来源:GenericListTest.cs

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

示例10: Main

        static void Main()
        {
            GenericList<int> test = new GenericList<int>(5);
            test.Add(56);
            test.Add(56);
            test.Add(56);
            test.Add(56);
            test.Add(56);
            test.Add(56);
            GenericList<string> test2 = new GenericList<string>(10);
            test2.Add("asdasda");
            test2.Add("sadasdsd");
            test2.RemoveElement(0);
            Console.WriteLine(test2.ElementByIndex(0));
            test.InsertAt(2, 57);
            Console.WriteLine(test.FindElementByValue(57));
            int t = GenericList<GenericList<string>>.Min<int>(67, 68);
            Console.WriteLine(t);

            //GenericList<int> testList = new GenericList<int>();
            //GenericList<string> testList2 = new GenericList<string>();
            //testList.Add(56);
            //Tuple<int, string> test = new Tuple<int, string>(5, "az");
            //Console.WriteLine(test.Item2);
            //int a = 5;
            //int b = 6;
            //int min = Max<int>(a, b);
            //Console.WriteLine(min);
        }
开发者ID:stefan-petrov,项目名称:TelerikAcademy,代码行数:29,代码来源:Test.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

        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

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

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

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


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