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


C# GenericList.GetElementAtIndex方法代码示例

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


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

示例1: Main

        static void Main()
        {
            //Create generic list
            GenericList<int> myList = new GenericList<int>(2);

            //Add elemnets
            myList.AddElement(30);
            myList.AddElement(2);
            myList.AddElement(3);

            Console.WriteLine(myList);

            //Access element by index
            Console.Write("The element at index 0 is: ");
            Console.WriteLine(myList.GetElementAtIndex(0));
            Console.WriteLine();

            //Remove element at certain index
            myList.RemoveElementAtIndex(1);
            Console.WriteLine("The element at index 1 has been removed!");
            Console.WriteLine(myList);

            //Insert element at certain index
            myList.InsertElementAtIndex(1, 800);
            Console.WriteLine("The element at index 1 has been inserted!");
            Console.WriteLine(myList);

            //Find index of value 800 and 3000
            Console.Write("The value 800 has index of: ");
            Console.WriteLine(myList.FindElement(800));
            Console.Write("The value 3000 has index of: ");
            Console.WriteLine(myList.FindElement(3000));

            //Min element in list
            Console.WriteLine();
            Console.Write("The min element is:");
            Console.WriteLine(myList.MinElement());

            //Max element in list
            Console.Write("The max element is:");
            Console.WriteLine(myList.MaxElement());
        }
开发者ID:sylviapsh,项目名称:18.DefiningClassesPartTwo,代码行数:42,代码来源:GenericListTestProgram.cs

示例2: Main

        static void Main()
        {
            //test Add and GetElementAtIndex
            GenericList<string> list = new GenericList<string>(1);
            list.Add("Zero");
            list.Add("One");
            string temp = list.GetElementAtIndex(1);
            Console.WriteLine(temp);
            list.Add("Two");
            temp = list.GetElementAtIndex(2);
            Console.WriteLine(temp);
            Console.WriteLine();

            //test Remove and Insert
            list.Remove(1);
            list.Insert(1, "Three");
            temp = list.GetElementAtIndex(1);
            Console.WriteLine(temp);
            temp = list.GetElementAtIndex(2);
            Console.WriteLine(temp);
            Console.WriteLine();

            //test Clear
            list.Clear();
            list.Add("Four");
            list.Add("Five");
            list.Add("Six");
            temp = list.GetElementAtIndex(0);
            Console.WriteLine(temp);
            temp = list.GetElementAtIndex(1);
            Console.WriteLine(temp);
            temp = list.GetElementAtIndex(2);
            Console.WriteLine(temp);
            Console.WriteLine();

            //test Find
            Console.WriteLine(list.Find("Six"));
            Console.WriteLine(list.Find("Seven"));
            Console.WriteLine();

            //test ToString
            Console.WriteLine(list.ToString());
        }
开发者ID:novocob,项目名称:TelerikAcademy,代码行数:43,代码来源:Tests.cs


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