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


C# GenericList.FindElement方法代码示例

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


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

示例1: Main

        static void Main()
        {
            GenericList<int> list = new GenericList<int>(3);
            GenericList<string> listNames = new GenericList<string>(2);

            listNames.Add("Pesho");
            listNames.Add("Avan");
            Console.WriteLine(listNames);
            Console.WriteLine(listNames.Min<string>());

            list.Add(1);
            list.Add(2);
            list.Add(1);

            //list.RemoveElement(2);
            //list.Clear();
            list.Insert(10, 0);
            list.Add(-3);
            list.Add(13);
            list.Add(3);
            list.TakeElement(1);
            Console.WriteLine(list);

            Console.WriteLine(list.FindElement(10));

            list.FindElement(2);

            Console.WriteLine("Minimal value: " + list.Min<int>());
            Console.WriteLine("Maximal value: " + list.Max<int>());
            Console.WriteLine("Capacity: " + list.Capacity);
            Console.WriteLine("Count: " + list.Count);
        }
开发者ID:ilian-ivanov,项目名称:Telerik-Academy,代码行数:32,代码来源:GenericListTest.cs

示例2: Main

 static void Main()
 {
     try
     {
         GenericList<int> list = new GenericList<int>(5);
         list.Add(1);
         list.Add(2);
         list.Add(1);
         Console.Write("Add : ");
         Console.WriteLine(list.ToString());
         list.Remove(1);
         Console.Write("Remove : ");
         Console.WriteLine(list.ToString());
         list.Insert(3, 555);
         Console.Write("Insert : ");
         Console.WriteLine(list.ToString());
         Console.Write("Clear : ");
         list.ClearList();
         Console.WriteLine(list.ToString());
         Console.WriteLine("Searching element by its value");
         list.Add(1);
         list.Add(2);
         list.Add(1);
         list.Add(2);
         list.Insert(2, 3);
         Console.WriteLine(list.ToString());
         int indexOfElement = list.FindElement(1, 1);
         Console.WriteLine(indexOfElement);
     }
     catch (ArgumentOutOfRangeException exp)
     {
         Console.WriteLine("Error!");
         Console.WriteLine(exp);
     }
 }
开发者ID:naturalna,项目名称:OOPPrinciples,代码行数:35,代码来源:GenericExample.cs

示例3: Main

        public static void Main()
        {
            GenericList<int> exampleGeneric = new GenericList<int>(3);
            Console.WriteLine("GenericList capacity = " + exampleGeneric.Capacity);
            Console.WriteLine("ToString method result = " + exampleGeneric.ToString());
            Console.WriteLine(new string('=', 30));

            exampleGeneric.Add(3);
            exampleGeneric.Add(4);
            exampleGeneric.Add(7);
            exampleGeneric.Add(12);
            Console.WriteLine("ToString method result after adding elements = " + exampleGeneric.ToString());
            Console.WriteLine(new string('=', 30));

            Console.WriteLine("The element at index 0 is " + exampleGeneric.GetItemAtIndex(0));
            Console.WriteLine("The element at index 1 is " + exampleGeneric.GetItemAtIndex(1));
            Console.WriteLine("The element at index 2 is " + exampleGeneric.GetItemAtIndex(2));
            Console.WriteLine("The element at index 3 is " + exampleGeneric.GetItemAtIndex(3));
            Console.WriteLine(new string('=', 30));

            exampleGeneric.RemoveElementAtIndex(0);
            Console.WriteLine("ToString method result after removing element at index 0 = " + exampleGeneric.ToString());
            exampleGeneric.RemoveElementAtIndex(2);
            Console.WriteLine("ToString method result after removing element at index 2 = " + exampleGeneric.ToString());
            Console.WriteLine(new string('=', 30));

            exampleGeneric.InsertElementAtIndex(3, 0);
            Console.WriteLine("ToString method result after inserting value of 3 at index 0 = " + exampleGeneric.ToString());
            exampleGeneric.InsertElementAtIndex(12, 2);
            Console.WriteLine("ToString method result after inserting value of 12 at index 1 = " + exampleGeneric.ToString());
            Console.WriteLine(new string('=', 30));

            Console.WriteLine("The index of 12 is " + exampleGeneric.FindElement(12));
            Console.WriteLine("The index of 3 is " + exampleGeneric.FindElement(3));
            Console.WriteLine("The index of 4 is " + exampleGeneric.FindElement(4));
            Console.WriteLine(new string('=', 30));

            Console.WriteLine("The min value is " + exampleGeneric.Min());
            Console.WriteLine("The max value is " + exampleGeneric.Max());
            Console.WriteLine(new string('=', 30));

            exampleGeneric.Clear();
            Console.WriteLine("ToString method result after clearing = " + exampleGeneric.ToString());
            Console.WriteLine(new string('=', 30));
        }
开发者ID:AyrFX,项目名称:Telerik-Academy-2015-Object-Oriented-Programming-Homeworks,代码行数:45,代码来源:GenericClassDemo.cs

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

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

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

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

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

示例9: Main

 static void Main(string[] args)
 {
     GenericList<int> list = new GenericList<int>();
     list.Add(45);
     list.Add(41);
     list.Add(2);
     list.Remove(1);
     list.Add(4);
     list.Insert(5, 1);
     list.Insert(12,3);
     int element = 5;
     list.FindElement(element);
     Console.WriteLine(list);
     Console.WriteLine("Element with max value is {0}", list.Max<int>());
     Console.WriteLine("Element with min value is {0}", list.Min<int>());
 }
开发者ID:vaskosound,项目名称:GenericList,代码行数:16,代码来源:TestList.cs

示例10: Main

        static void Main()
        {
            GenericList<int> someList = new GenericList<int>(10);
            someList.Add(7);
            Console.WriteLine(someList[0]);
            someList.Add(3846);
            Console.WriteLine("Element 3846 is at position {0}", someList.FindElement(3846));

            Console.WriteLine("Min: {0}", someList.Min());

            Console.WriteLine("Max: {0}", someList.Max());

            Console.WriteLine(someList);

            someList.Remove(0);
            Console.WriteLine(someList[0]);
        }
开发者ID:vphilipov,项目名称:TelerikAcademy,代码行数:17,代码来源:Program.cs

示例11: Main

 static void Main()
 {
     GenericList<int> testList = new GenericList<int>(4);
     testList.AddElement(10);
     testList.AddElement(15);
     testList.AddElement(50);
     testList.AddElement(30);
     Console.WriteLine("Initial list contents:\n"+testList);
     testList.RemoveAt(1);
     Console.WriteLine("Minimal element: {0} Maximal element: {1}\n",testList.Min(),testList.Max());
     Console.WriteLine("List contents after element at index 1 is removed:\n" + testList);
     testList.InsertAt(20, 1);
     Console.WriteLine("List contents after inserting 20 at index 1:\n" + testList);
     int indexOfElement = testList.FindElement(50);
     Console.WriteLine("Index of element with value equal to 50 ---> " + indexOfElement+"\n");
     Console.WriteLine("Capacity before adding element to overfill internal array:" + testList.Capacity+"\n");
     testList.AddElement(40);
     Console.WriteLine("Capacity after adding element(auto-grow functionality is tested here):" + testList.Capacity + "\n");
     testList.Clear();
     Console.WriteLine("List contents after list is cleared:");
 }
开发者ID:plwh,项目名称:TelerikHomework,代码行数:21,代码来源:GenericList_Main.cs

示例12: Main

    static void Main()
    {
        GenericList<int> listTesting = new GenericList<int>(1);
        listTesting.AddElement(2);
        listTesting.AddElement(3);
        listTesting.AddElement(4);
        listTesting.AddElement(5);
        listTesting.AddElement(6);
        listTesting.AddElement(-1000);

        Console.WriteLine(listTesting);
        listTesting.RemoveElement(5);
        Console.WriteLine(listTesting);
        listTesting.InsertElement(0,25);
        Console.WriteLine(listTesting);
        Console.WriteLine(listTesting.FindElement(25));
        Console.WriteLine(listTesting.Max());
        Console.WriteLine(listTesting.Min());
        listTesting.ClearList();
        Console.WriteLine(listTesting);
    }
开发者ID:pepakam,项目名称:TelerikAcademy,代码行数:21,代码来源:Program.cs

示例13: Main

        static void Main()
        {
            try
            {
                GenericList<int> itemsList = new GenericList<int>();
                itemsList.Add(5);
                itemsList.Add(11);
                itemsList.Add(2);
                itemsList.Add(-4);

                itemsList.InsertAt(1, 9);
                Console.WriteLine(itemsList.FindAt(1));
                Console.WriteLine(itemsList.FindElement(15));
                Console.WriteLine(itemsList.Min());
                Console.WriteLine(itemsList.Max());
                itemsList.ToString();

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:stoyans,项目名称:Telerik,代码行数:23,代码来源:Program.cs

示例14: Main

        static void Main()
        {
            Point3D point1 = new Point3D(1, 2, 3);
            Console.WriteLine(point1);
            Console.WriteLine(Point3D.InitialPoint);

            Point3D point2 = new Point3D(3, 4, 5);
            Console.WriteLine(point2);
            decimal distance = StaticPoint3D.CalculateDistance(point1, point2);
            Console.WriteLine(distance);

            Random rand = new Random();
            var path = new List<Path>();
            for (int i = 0; i < 5; i++)
            {
                Path point = new Path(new Point3D(rand.Next(0, 51), rand.Next(0, 51), rand.Next(0, 51)));
                path.Add(point);
            }

            PathStorage.SavePath(path);
            PathStorage.LoadPath();
            foreach (var point in PathStorage.ListOfPath)
            {
                Console.WriteLine(point);
            }

            var list = new GenericList<int>();
            list.Add(5);
            list.Add(53);
            list.Add(545);
            list.Add(5);
            list.Add(53);
            list.Add(545);
            Console.WriteLine(list[2]);
            list.RemoveAt(5);
            list.Add(5);
            Console.WriteLine(list[4]);
            Console.WriteLine(list.Count);
            list.Insert(1, 2);
            Console.WriteLine(list.FindElement(5));
            Console.WriteLine(list);
            list.Clear();

            for (int i = 0; i < 16; i++)
            {
                list.Add(2);
            }
            list.Insert(1, 5);
            Console.WriteLine(list.Max());
            Console.WriteLine(list.Min());

            var listStr = new GenericList<string>();
            listStr.Add("pesho");
            Console.WriteLine(listStr[0]);

            Matrix<int> matrix = new Matrix<int>();
            matrix[0, 0] = 5;
            matrix[1, 0] = 2;

            Matrix<int> matrix1 = new Matrix<int>();
            matrix1[0, 0] = 5;
            matrix1[1, 0] = 2;

            Matrix<int> resultSum = matrix + matrix1;
            Matrix<int> resultSub = matrix - matrix1;
            Matrix<int> resultMul = matrix * matrix1;

            //matrix[0, 1] = 5;
            //matrix[1, 1] = 2;

            if(matrix)
            {
                Console.WriteLine("There is non-zero elements!");
            }
            else
            {
                Console.WriteLine("There is zero elements!");
            }

            var attributes = typeof(PathStorage).GetCustomAttributes(true);
            foreach (var attr in attributes)
            {
                var versionAttr = (VersionAtribute)attr;
                Console.WriteLine(versionAttr.Version);
            }
        }
开发者ID:TeeeeeC,项目名称:TelerikAcademy2015-2016,代码行数:86,代码来源:Test.cs

示例15: Main

        static void Main()
        {
            // Version:
            var allAttributes = typeof(GenericList<>).GetCustomAttributes(typeof(VersionAttribute), false);
            Console.WriteLine("Version: " + allAttributes[0]);
            Console.WriteLine();

            // Example 1:
            Console.WriteLine("Example 1:");
            GenericList<int> nums = new GenericList<int>(3);
            nums.Add(2);
            nums.Add(4);
            nums.Add(6);
            nums.Add(8);
            nums.Add(7);
            Console.WriteLine(nums);

            Console.Write("Accessing element by index [2]: ");
            Console.WriteLine(nums[2]);

            Console.Write("Removing element by index [1]: ");
            nums.RemoveByIndex(1);
            Console.WriteLine(nums);

            Console.Write("Inserting element by index [2], element = 10: ");
            nums.InsertByIndex(2, 10);
            Console.WriteLine(nums);

            Console.Write("The element with the maximum value in the list: ");
            Console.WriteLine(nums.Max());
            Console.Write("The element with the minimum value in the list: ");
            Console.WriteLine(nums.Min());

            Console.Write("Finding element index by value: ");
            Console.WriteLine(nums.FindElement(7));

            Console.Write("Checking if the list contains a value: ");
            Console.WriteLine(nums.Contains(-10));

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

            // Example 2:
            Console.WriteLine("Example 2:");
            GenericList<string> dogNames = new GenericList<string>(2);
            dogNames.Add("Sharo");
            dogNames.Add("Rex");
            dogNames.Add("Blackie");
            dogNames.Add("Rich");
            dogNames.Add("Bella");
            Console.WriteLine(dogNames);

            Console.Write("Accessing element by index [3]: ");
            Console.WriteLine(dogNames[3]);

            Console.Write("Removing element by index [2]: ");
            dogNames.RemoveByIndex(2);
            Console.WriteLine(dogNames);

            Console.Write("Inserting element by index [0], element = 'Izzy': ");
            dogNames.InsertByIndex(0, "Izzy");
            Console.WriteLine(dogNames);

            Console.Write("The element with the maximum value in the list: ");
            Console.WriteLine(dogNames.Max());
            Console.Write("The element with the minimum value in the list: ");
            Console.WriteLine(dogNames.Min());

            Console.Write("Finding element index by value('Izzy'): ");
            Console.WriteLine(dogNames.FindElement("Izzy"));

            Console.Write("Checking if the list contains a value('Rich'): ");
            Console.WriteLine(dogNames.Contains("Izzy"));       
        }
开发者ID:bnaskov,项目名称:SoftUni,代码行数:76,代码来源:Demo.cs


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