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


C# GenericList.InsertElement方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            GenericList<int> list = new GenericList<int>(6);

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

            //list.InsertElement(0, 9);
            list.InsertElement(0, 9);
            list.InsertElement(0, 9);
            list.InsertElement(0, 9);

            //Console.WriteLine(list.Contains(4));
            //Console.WriteLine(list.FindElement(9));
            //list.RemoveElement(6);

            var type = typeof (GenericList<>);
            var genericListAttributeVersion = type.GetCustomAttribute(typeof(Version), false);
            var attributeVersion = (Version)genericListAttributeVersion;

            Console.WriteLine("Current version is: {0}.{1}", attributeVersion.Major, attributeVersion.Minor);
        }
开发者ID:EmilAleksandrov,项目名称:OOP,代码行数:25,代码来源:Test.cs

示例2: Main

 static void Main()
 {
     Console.WriteLine("Hello World.");
     Console.WriteLine("Make new List.");
     GenericList<float> newList = new GenericList<float>(20);
     Console.WriteLine("Add some numbers to the List - 5.3, 6.27, 7.55, 8, 9.09");
     newList.AddElement(5.3f);
     newList.AddElement(6.27f);
     newList.AddElement(7.55f);
     newList.AddElement(8f);
     newList.AddElement(9.09f);
     Console.WriteLine("Print Max element: {0}", newList.Max());
     Console.WriteLine("Print Min element: {0}", newList.Min());
     Console.WriteLine("Add 10 in the biggining.");
     newList.InsertElement(0, 10);
     Console.WriteLine("Print Max element again: {0}", newList.Max());
     Console.WriteLine("Print the List.");
     Console.WriteLine(newList);
     Console.WriteLine("Remove the fourth element.");
     newList.RemoveElement(3);
     Console.WriteLine("Print the List.");
     Console.WriteLine(newList);
     Console.WriteLine("Remove the fourth element.");
     newList.RemoveElement(3);
     Console.WriteLine("Print the List.");
     Console.WriteLine(newList);
     Console.WriteLine("Remove the fourth element.");
     newList.RemoveElement(3);
     Console.WriteLine("Print the List.");
     Console.WriteLine(newList);
     Console.WriteLine("Add 15.56 in the end.");
     newList.InsertElement(3, 15.56f);
     Console.WriteLine("Print the List.");
     Console.WriteLine(newList);
 }
开发者ID:Nikolai-Aleksiev,项目名称:Telerik-Academy-HomeWorks,代码行数:35,代码来源:GenericTest.cs

示例3: Main

 static void Main()
 {
     GenericList<int> arr = new GenericList<int>();
     arr.Add(5);
     arr.Add(6);
     arr.InsertElement(3, 1);
     arr.InsertElement(2, 4);
     arr.Contain(5);
     Console.WriteLine(arr.Contain(15));
     Console.WriteLine(arr);
 }
开发者ID:MiroslavTonev,项目名称:Homework-OOP,代码行数:11,代码来源:Program.cs

示例4: Main

        static void Main()
        {
            Path p = new Path();
            p.AddPoint(new Point3D(1, 2, 3));
            p.AddPoint(new Point3D(5, 2, 6));
            p.AddPoint(new Point3D(1, 3, 5));
            p.AddPoint(new Point3D(-5, 2, 3));
            p.AddPoint(new Point3D(-2, -10, 3));

            PathStorage.SavePath(p); //Save path in file savedPaths.txt
            Path final = PathStorage.LoadPath(); //loading from the file savedPaths.txt
            final.PrintPathList(); //printing the loaded path

            ////05, 06, 07->

            GenericList<int> list = new GenericList<int>();
            list.AddElement(10);
            list.AddElement(5);
            list.AddElement(4);
            list.InsertElement(1, 15);
            list.InsertElement(1, 12);
            Console.WriteLine(list.ToString());
            Console.WriteLine();
            list[0] = 5;
            int min = list.Min();
            int max = list.Max();
            Console.WriteLine(min);
            Console.WriteLine(max);
            list.Clear();
            Console.WriteLine(list.ToString());

            /////08, 09, 10 ->

            double[,] first = { { 0, 2, 3, 4.2 }, { 1, 2, 3, 4 }, { 1, 2, 3, 4 }, { 1, 2, 3, 4 } };
            double[,] second = { { 1, 2, 3, 4 }, { 1, 2, 3, 4 }, { 1, 2, 3, 4 }, { 1, 0, 3, 4 } };

            Matrix<double> arrFirst = new Matrix<double>(first);
            Matrix<double> arrSecond = new Matrix<double>(second);

            //checking if contain zero, return true, if not, return false if there is zero
            if (arrFirst)
            {
                Console.WriteLine("There is no zero inside");
            }
            else Console.WriteLine("There is at least one zero inside\n");
            //-----------
            Console.WriteLine("Sum of the two matrices");
            Console.WriteLine(arrFirst + arrSecond);
            Console.WriteLine("Substraction of the two matrices");
            Console.WriteLine(arrFirst - arrSecond);
            Console.WriteLine("Multiplication of the two matrices");
            Console.WriteLine(arrFirst * arrSecond);
        }
开发者ID:prestress,项目名称:Telerik_Academy_Homework_Projects,代码行数:53,代码来源:Program.cs

示例5: Main

        static void Main(string[] args)
        {
            GenericList<object> processingGenericList = new GenericList<object>();
            object[] list;


            //Testing

            processingGenericList.AddElement(0);
            processingGenericList.AddElement(1);
            processingGenericList.AddElement(2);
            processingGenericList.InsertElement(15,8);
            processingGenericList.AddElement(3);
            processingGenericList.AddElement(4);
            processingGenericList.AddElement(5);
            processingGenericList.AddElement(-1);
            processingGenericList.AddElement(7);
            processingGenericList.AddElement(8);
               
            list = processingGenericList.returnList();
            for (int i = 0; i < list.Length; i++)
            {
               Console.WriteLine(list[i]);
            }

            Console.WriteLine("Min is: " + processingGenericList.Min());
            Console.WriteLine("Max is: " + processingGenericList.Max());
        }
开发者ID:vaster,项目名称:Telerik.vasko,代码行数:28,代码来源:Core.cs

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

示例7: Main

 static void Main()
 {
     GenericList<int> list = new GenericList<int>();
     list.AddElement(10);
     list.AddElement(5);
     list.AddElement(4);
     list.InsertElement(1, 15);
     list.InsertElement(1, 12);
     Console.WriteLine(list.ToString());
     Console.WriteLine();
     list[0] = 5;
     int min = list.Min();
     int max = list.Max();
     Console.WriteLine(min);
     Console.WriteLine(max);
     list.Clear();
     Console.WriteLine(list.ToString());
 }
开发者ID:Bvaptsarov,项目名称:Homework,代码行数:18,代码来源:TestGenericList.cs

示例8: Main

        static void Main(string[] args)
        {
            /*Testing is it working!*/

            GenericList<int> testingGenerics = new GenericList<int>(1);

            // Getting elements:
            testingGenerics.AddElement(1);
            testingGenerics.AddElement(2);
            testingGenerics.AddElement(3);
            testingGenerics.AddElement(4);
            testingGenerics.AddElement(5);
            testingGenerics.AddElement(6);
            Console.WriteLine("The Array is: ");
            Console.WriteLine(testingGenerics);

            // Testing indexator:
            Console.Write("The int on index [3] is: ");
            Console.WriteLine(testingGenerics[3]);
            Console.Write("Changing it to 99: ");
            testingGenerics[3] = 99;
            Console.WriteLine(testingGenerics[3]);

            // Testing remove by index:
            Console.WriteLine();
            Console.WriteLine("Removing element [1]:");
            testingGenerics.RemoveElement(1);
            Console.Write("The new array is: ");
            Console.WriteLine(testingGenerics);

            // Testing the inserting by index:
            Console.WriteLine("Inserting a new element with index[0] = 100");
            testingGenerics.InsertElement(0, 100);
            Console.Write("The new array is: ");
            Console.WriteLine(testingGenerics);

            // Testing element counter:
            Console.WriteLine("The count of elements is: " + testingGenerics.Count);

            // Finding element:
            Console.Write("The element 3 is on index : ");
            Console.WriteLine(testingGenerics.FindElement(3));
            Console.WriteLine();

            //Testing to string
            Console.Write("To String: ");
            Console.WriteLine(testingGenerics.ToString());

            //Testing min & max element
            Console.WriteLine("Min element is: " + testingGenerics.MinElement());
            Console.WriteLine("Max element is: " + testingGenerics.MaxElement());
            Console.WriteLine();

            //clearing the list
            testingGenerics.Clear();
            Console.WriteLine("Cleared array: " + testingGenerics);
        }
开发者ID:Jarolim,项目名称:HomeWork,代码行数:57,代码来源:TestingGenericList.cs

示例9: Main

        static void Main(string[] args)
        {
            GenericList<string> genericList = new GenericList<string>();

            genericList.Add("4");
            genericList.Add("3");
            genericList.Add("6");
            genericList.Add("9");
            Console.WriteLine(String.Join(", ", genericList.element));
            genericList.InsertElement(1, "6");

            Console.WriteLine(genericList.Min("Pesho", "Gosho"));
        }
开发者ID:HristoHristov,项目名称:OOP,代码行数:13,代码来源:MainMethod.cs

示例10: 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.
        //6. Implement auto-grow functionality: when the internal array
        //is full, create a new array of double size and move all elements to it.
        //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.
        static void Main()
        {
            //this class is for testing purposes

            GenericList<int> testList = new GenericList<int>(1);

            //adding some elements
            testList.AddElement(15);
            testList.AddElement(10);
            testList.AddElement(49);
            testList.AddElement(18);

            //testing indexator
            Console.WriteLine(testList[1]);
            testList[1] = 56;
            Console.WriteLine(testList[1]);

            //testing remove by index
            testList.RemoveElement(1);
            Console.WriteLine(testList[1]);
            testList.AddElement(1);
            testList.RemoveElement(testList.Count - 1);

            //inserting by index
            testList.InsertElement(0, 100);

            //testing element counter
            Console.WriteLine("Count: " + testList.Count);

            //find element
            Console.WriteLine(testList.FindElement(49));

            //to string
            Console.WriteLine(testList.ToString());

            testList.AddElement(1);
            testList.AddElement(1);
            testList.AddElement(1);
            testList.AddElement(1);
            testList.AddElement(1);
            testList.AddElement(1);

            //min & max element
            Console.WriteLine(testList.MinElement());
            Console.WriteLine(testList.MaxElement());

            //clearing the list
            testList.Clear();
            Console.WriteLine();
        }
开发者ID:Jarolim,项目名称:HomeWork,代码行数:62,代码来源:Program.cs

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

示例12: Main

        static void Main()
        {
            GenericList<int> test = new GenericList<int>();
            test.AddElement(5);
            test.AddElement(6);
            test.AddElement(7);
            test.AddElement(8);
            test.AddElement(9);

            //testing method add
            Console.WriteLine(test);
            //testing insert method
            Console.WriteLine("Insert element 2 at position 4");
            test.InsertElement(4, 2);
            Console.WriteLine(test);
            //testing method remove
            Console.WriteLine("Removing element at pos 5");
            test.RemoveAtIndex(5);
            Console.WriteLine(test);
            int result = test.AccessElement(3);
            Console.WriteLine("Accessing element at index 3: ");
            Console.WriteLine(result);
            Console.WriteLine("Finding element by value '0': ");
            Console.WriteLine(test.FindElementByValue(0));

            Console.WriteLine("Clear!");
            test.ClearingList();
            Console.WriteLine(test);
            Console.WriteLine();
            Console.WriteLine("Doubling the size:");
            for (int i = 1; i < 15; i++)
            {
                test.AddElement(i);
            }
            //test.AddElement(1);
            Console.WriteLine(test);
            //testing min max
            Console.WriteLine("Biggest, smallest: ");
            Console.WriteLine(test.Max<int>());
            Console.WriteLine(test.Min<int>());
        }
开发者ID:joro1881,项目名称:CSharpProgramming,代码行数:41,代码来源:ValidationUnit.cs

示例13: Main

        static void Main(string[] args)
        {
            GenericList<int> arrayGenerics = new GenericList<int>(10);

            arrayGenerics.AddElement(4);
            arrayGenerics.AddElement(2222);
            arrayGenerics.AddElement(2212);
            arrayGenerics.Clear();
            arrayGenerics.AddElement(4);
            arrayGenerics.AddElement(2);
            arrayGenerics.AddElement(22222);
            arrayGenerics.RemoveElemenByIndext(0);

            arrayGenerics.InsertElement(0, 213321);
            arrayGenerics.RemoveElemenByIndext(0);
            Console.WriteLine(arrayGenerics.ToString());
            Console.WriteLine();

            Console.WriteLine("Max:"+arrayGenerics.Max());
            Console.WriteLine("Min:"+arrayGenerics.Min());
        }
开发者ID:kikooo52,项目名称:C-Programs,代码行数:21,代码来源:Program.cs

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

示例15: Main

    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.RemoveElement(5);
        Console.WriteLine(listTesting);
        listTesting.InsertElement(0,25);
        Console.WriteLine(listTesting);
        Console.WriteLine(listTesting.FindElement(25));
        Console.WriteLine(listTesting.Max());
        Console.WriteLine(listTesting.Min());
        listTesting.ClearList();
        Console.WriteLine(listTesting);
    }
开发者ID:pepakam,项目名称:TelerikAcademy,代码行数:21,代码来源:Program.cs


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