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


C# GenericList.FindElementIndex方法代码示例

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


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

示例1: Main

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

            numbers.Add(15);
            numbers.Add(20);
            numbers.Add(100);
            numbers.Add(-200);
            numbers.Add(-20);
            //remove at position 2 (this is 100)
            numbers.RemoveAt(2);

            //print element on position 2
            //the output is -200
            Console.WriteLine(numbers[2]);

            //check method for finding element
            int index = numbers.FindElementIndex(-20);
            Console.WriteLine("The index of {0} is {1}", -20, index);

            //if there is no such element the result is -1
            index = numbers.FindElementIndex(-30);
            if (index < 0)
            {
                Console.WriteLine("There is no such element!");
            }

            //test the override ToString method
            Console.WriteLine(numbers.ToString());

            //test Min and Max methods
            Console.WriteLine(numbers.Max());
            Console.WriteLine(numbers.Min());

            numbers.Clear();
        }
开发者ID:jesusico83,项目名称:Telerik,代码行数:36,代码来源:GenericListTester.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()
        {
            // creating an initial array
            GenericList<int> testArray = new GenericList<int>(4);
            Console.WriteLine("The GenericList has {0} elements", testArray.Count);
            Console.WriteLine("The initial capacity is {0}\n", testArray.Capacity);

            // adding elemnts
            for (int i = 1; i < 5; i++)
            {
                testArray.Add(i * 5);
            }
            Console.WriteLine("Now in the GenericList you have {0} elements ", testArray.Count);
            Console.WriteLine("The object at position 1 is {0}\n", testArray[1]);

            // test To.String() method
            Console.WriteLine("ToString {0}\n", testArray);

            // test InsertAt method and FindElementIndex method
            var insertInt = 30;
            testArray.InsertAt(1, insertInt);

            Console.WriteLine("Capacity after AutoGrow is {0}", testArray.Capacity);
            Console.WriteLine("You can find {0} at index {1}"
                , insertInt, testArray.FindElementIndex(insertInt));
            Console.WriteLine("ToString {0}\n", testArray);

            // test RemoveAt method
            testArray.RemoveAt(1);

            Console.WriteLine("Now on position 1 is {0} and the count is {1}", testArray[1], testArray.Count);
            Console.WriteLine("ToString {0}\n", testArray);

            // test Min and Max
            Console.WriteLine("The smallest element is {0} and the biggest is {1}\n"
                , testArray.MinT(), testArray.MaxT());

            // test Clear method
            testArray.ClearList();
            Console.WriteLine("After clear there are {0} elements in the array\n", testArray.Count);
        }
开发者ID:tddold,项目名称:TelerikAcademyHomework,代码行数:41,代码来源:TestGeneric.cs


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