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


C# GenericList.ElementAt方法代码示例

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


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

示例1: Main

        static void Main()
        {
            GenericList<int> listInt = new GenericList<int>();
            GenericList<string> listString = new GenericList<string>(60);

            listInt.Add(5);
            listInt.Add(6);
            listInt.Add(7);
            listInt.Add(8);

            listString.Add("Generic");
            listString.Add("List");
            int takeElement = listInt.ElementAt(0);

            // list.InsertAt(1, 5);
            // list.RemoveAt(0);
            // list.Clean();
            // int index = list.GetIndex(5);
            // int capacity = list.Capacity;
            // int count = list.Count;

            int min = listInt.Min();
            int max = listInt.Max();

            string minString = listString.Min();
            string maxString = listString.Max();

            Console.WriteLine(listInt);

            Console.WriteLine(listString);
        }
开发者ID:jerko0,项目名称:Telerik-Academy,代码行数:31,代码来源:tastFrom5to7.cs

示例2: Main

        public static void Main()
        {
            GenericList<int> test = new GenericList<int>();
            
            Console.WriteLine("Adding an elements: ");
            test.Add(1);
            test.Add(2);
            test.Add(5);
            test.Add(15);
            Console.WriteLine(test);

            Console.WriteLine("Accessing element by index: 3");
            Console.WriteLine(test.ElementAt(3) + "\n");

            Console.WriteLine("Removing element by index: 2");
            test.RemoveAt(2);
            Console.WriteLine(test);

            Console.WriteLine("Inserting element at given position: 0");
            test.InsertAt(0, 100);
            Console.WriteLine(test);

            Console.WriteLine("Finding element index by given value: 2");
            var index = test.FindElementIndex(2);
            Console.WriteLine(index != null ? index.ToString() : "No such element.");
            Console.WriteLine();

            Console.WriteLine("Checking if the list contains values: 100 and 55");
            Console.WriteLine(test.Countains(100));
            Console.WriteLine(test.Countains(55) + "\n");

            Console.WriteLine("Max element:");
            Console.WriteLine(test.Max() + "\n");

            Console.WriteLine("Min element:");
            Console.WriteLine(test.Min() + "\n");

            Console.WriteLine("Clearing the list:");
            test.Clear();
            Console.WriteLine(test);

            Type type = typeof(GenericList<>);
            object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), false);
            Console.WriteLine("Version: {0}", (allAttributes[0] as VersionAttribute).Version);
        }
开发者ID:nok32,项目名称:SoftUni,代码行数:45,代码来源:GenericListTest.cs

示例3: Main

        static void Main()
        {
            var genList = new GenericList<int>(0);
            genList.Add(1);
            genList.Add(2);
            genList.Add(3);
            genList.Add(4);
            genList.Add(5);
            genList.Add(12);
            genList.Insert(0, 6);
            genList.Insert(0, 6);
            genList.Insert(0, 6);
            genList.Insert(0, 6);
            genList.Insert(0, 6);
            genList.Insert(0, 6);
            Console.WriteLine(genList.ElementAt(1));

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

            Console.WriteLine(new string('=', 50));
            genList.RemoveAt(1);
            Console.WriteLine(genList.ToString());

            genList.Insert(1, 2);
            Console.WriteLine(genList.ToString());

            genList.Insert(12, 0);
            Console.WriteLine(genList.ToString());

            var idxof = (genList.IndexOf(2));
            Console.WriteLine(idxof);

            genList.Clear();
            Console.WriteLine(genList.ToString());



            List<int> list = new List<int>();
        }
开发者ID:damy90,项目名称:Telerik-all,代码行数:40,代码来源:GenListTest.cs

示例4: Main

        static void Main(string[] args)
        {
            GenericList<string> names = new GenericList<string>();
            names.Add("Penka");
            names.Add("Gloriq");
            names.Add("Tiranka");
            names.Add("Shishka");
            names.Add("Ivan");
            names.Add("Bobi");
            names.Add("Ivana");
            names.Add("Mariika");
            names.Add("Todor");
            names.Add("Plitka");
            names.Add("Ema");
            names.Add("Gosho");
            names.Add("Reneta");
            names.Add("Petq");
            names.Add("Pesho");
            names.Add("Eli");
            names.Add("Tina");

            Console.WriteLine(names.Count); //17

            int index = names.IndexOf("Pesho");
            Console.WriteLine(index); //14

            int index1 = names.IndexOf("SuperLubo");
            Console.WriteLine(index1); //-1

            names.RemoveAt(3); //removes Shishka
            Console.WriteLine(names.Count); //16

            //names.RemoveAt(18); exception

            names.InsertAt("Shishka", 3); //add again Shishka

            //names.InsertAt("Boris", 18); exception

            Console.WriteLine(names.Contains("Gosho")); //true
            Console.WriteLine(names.Contains("Mariq")); //false

            Console.WriteLine(names.ElementAt(9)); //Plitka

            //Console.WriteLine(names.ElementAt(32)); exception

            Console.WriteLine(names);

            names.Clear();
            Console.WriteLine(names.Count); //0

            GenericList<int> nums = new GenericList<int>();
            nums.Add(5);
            nums.Add(3);
            nums.Add(1234);

            int min = GenericListExtension.Min(nums.ElementAt(0), nums.ElementAt(1));
            Console.WriteLine(min);

            int max = GenericListExtension.Max(nums.ElementAt(1), nums.ElementAt(2));
            Console.WriteLine(max);

            //print the version attribute
            System.Reflection.MemberInfo info = typeof(GenericList<>);
            foreach (object attribute in info.GetCustomAttributes(false))
            {
                Console.WriteLine(attribute);
            }
        }
开发者ID:mdamyanova,项目名称:Fundamental-Level,代码行数:68,代码来源:MainProgram.cs

示例5: Main

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

            Console.WriteLine("Creating an int generic list of length 2");
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Number of elements: {0}", intList.Count);
            Console.WriteLine("Length: {0}", intList.Length);

            intList.Add(3);
            intList.Add(5);
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Adding 2 elements.");
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Number of elements: {0}", intList.Count);
            Console.WriteLine("Length: {0}", intList.Length);
            Console.WriteLine();
            Console.WriteLine("Elements:");
            Console.WriteLine(intList.ToString());

            intList.Add(7);
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Adding another element.");
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Number of elements: {0}", intList.Count);
            Console.WriteLine("Length: {0}", intList.Length);
            Console.WriteLine();
            Console.WriteLine("Elements:");
            Console.WriteLine(intList.ToString());

            intList.Clear();
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Clearing list.");

            intList.InsertAt(0, 2);
            intList.InsertAt(0, 2);
            intList.InsertAt(1, 3);
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Inserting elements.");
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Number of elements: {0}", intList.Count);
            Console.WriteLine("Length: {0}", intList.Length);
            Console.WriteLine();
            Console.WriteLine("Elements:");
            Console.WriteLine(intList.ToString());

            intList.RemoveAtIndex(0);
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Removing an element.");
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Number of elements: {0}", intList.Count);
            Console.WriteLine("Length: {0}", intList.Length);
            Console.WriteLine();
            Console.WriteLine("Elements:");
            Console.WriteLine(intList.ToString());

            var element  = intList.ElementAt(0);
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Element at index 0 is {0}.", element);

            element = intList.IndexOf(3);
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("The index of element 3 is {0}.", element);

            var max = intList.Max();
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("The max element is {0}.", max);

            var min = intList.Min();
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("The min element is {0}.", min);

        }
开发者ID:Vyara,项目名称:Telerik-Academy,代码行数:73,代码来源:GenericListTest.cs


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