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


C# GenericList.MinElement方法代码示例

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


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

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

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

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


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