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


C# GenericList.AddElement方法代码示例

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


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

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

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

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

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

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

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

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

示例8: AddingElements

 public void AddingElements()
 {
     GenericList<string> generic = new GenericList<string>(2);
     generic.AddElement("Pesho");
     generic.AddElement("Gosho");
     Assert.AreEqual("[Pesho, Gosho]", generic.ToString());
 }
开发者ID:abaditsegay,项目名称:SVN,代码行数:7,代码来源:UnitTest1.cs

示例9: AutoGrowTest

 public void AutoGrowTest()
 {
     GenericList<string> generic = new GenericList<string>(2);
     generic.AddElement("Pesho");
     generic.AddElement("Gosho");
     generic.AddElement("Kircho");
     Assert.AreEqual(4, generic.Count);
 }
开发者ID:abaditsegay,项目名称:SVN,代码行数:8,代码来源:UnitTest1.cs

示例10: FindElementTest

 public void FindElementTest()
 {
     GenericList<string> generic = new GenericList<string>(2);
     generic.AddElement("Pesho");
     generic.AddElement("Gosho");
     generic.AddElement("Kircho");
     int index = generic.FindElement("Kircho");
     Assert.AreEqual(2, index);
 }
开发者ID:abaditsegay,项目名称:SVN,代码行数:9,代码来源:UnitTest1.cs

示例11: AccessByIndexException

        public void AccessByIndexException()
        {
            GenericList<string> myList = new GenericList<string>(3);

            myList.AddElement("alpha");
            myList.AddElement("beta");
            myList.AddElement("gama");

            var actual = myList[3];
        }
开发者ID:rnikiforova,项目名称:TelerikAcademy,代码行数:10,代码来源:UnitTest1.cs

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

示例13: AutoGrowTest2

 public void AutoGrowTest2()
 {
     //two times autogrow
     GenericList<int> generic = new GenericList<int>(2);
     generic.AddElement(1);
     generic.AddElement(2);
     generic.AddElement(3);
     generic.AddElement(4);
     generic.AddElement(5);
     Assert.AreEqual(8, generic.Count);
 }
开发者ID:abaditsegay,项目名称:SVN,代码行数:11,代码来源:UnitTest1.cs

示例14: Main

        public static void Main()
        {
            GenericList<string> strings = new GenericList<string>(10);

            strings.AddElement("Nikolai");
            strings.AddElement("Mishev");
            Console.WriteLine(strings[0]+ "-" + strings[1]);

            Console.WriteLine(strings.Count.ToString());
            Console.WriteLine(strings.FindElement("Nilai"));
        }
开发者ID:NikolaiMishev,项目名称:Telerik-Academy,代码行数:11,代码来源:Testing.cs

示例15: AddingElementString

        public void AddingElementString()
        {
            GenericList<string> myList = new GenericList<string>(3);

            myList.AddElement("alpha");
            myList.AddElement("beta");

            var expected = "alphabeta";
            var actual = "" + myList[0] + myList[1] + myList[2];

            Assert.AreEqual(expected, actual);
        }
开发者ID:rnikiforova,项目名称:TelerikAcademy,代码行数:12,代码来源:UnitTest1.cs


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