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


C# GenericList.Find方法代码示例

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


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

示例1: Main

        static void Main()
        {
            string decorationLine = new string('-', 80);
            Console.Write(decorationLine);
            Console.WriteLine("***Creating and clearing lists of some type. Adding, removing, accessing, finding, inserting elements.***");
            Console.Write(decorationLine);

            Console.WriteLine("---Creating an empty list of strings---");
            GenericList<string> list = new GenericList<string>();
            Console.WriteLine("Empty list count: " + list.Count);
            Console.WriteLine("Empty list capacity: " + list.Capacity);

            Console.WriteLine("\n---Adding some elements to the list---");
            for (int count = 0; count < 16; count++)
            {
                list.Add("element " + (count + 1));
            }
            Console.WriteLine("The elements of the list are: " + list.ToString());
            Console.WriteLine("After adding some elements list count: " + list.Count);
            Console.WriteLine("After adding some elements list capacity: " + list.Capacity);

            Console.WriteLine("\n---Printing elements at specific indexes---");
            Console.WriteLine("Printing element with index 5: " + list[5]);
            Console.WriteLine("Printing element with index 0: " + list[0]);

            Console.WriteLine("\n---Removing some elements from the list---");
            list.RemoveAt(5);
            list.RemoveAt(0);
            list.RemoveAt(12);
            Console.WriteLine("After removing elements from the list: " + list.ToString());
            Console.WriteLine("Current list count: " + list.Count);

            Console.WriteLine("\n---Inserting some elements to the list---");
            list.InsertAt("string 5", 5);
            list.InsertAt("appear", list.Count - 1);
            list.InsertAt("string11", list.Count);
            Console.WriteLine("The new list is: " + list.ToString());
            Console.WriteLine("The new list count is: " + list.Count);

            Console.WriteLine("\n---Finding specific elements from the list---");
            Console.WriteLine("The index of 'element 9' is: " + list.Find("element 9"));
            Console.WriteLine("The index of 'element 111' is: " + list.Find("element 111"));

            Console.WriteLine("\n---Finding the maximal and the minimal element in the list---");
            Console.WriteLine("The minimal element in the list is: " + list.Min());
            Console.WriteLine("The maximal element in the list is: " + list.Max());

            Console.WriteLine("\n---Clearing the list---");
            list.Clear();
            Console.WriteLine("List count after clearing the list: " + list.Count);
            Console.WriteLine("List capacity after clearing the list: " + list.Capacity);

            // We cannot use Min() and Max() on "test" because it doesn't implement IComparable<>
            GenericList<Point2D> test = new GenericList<Point2D>();
            test.Add(new Point2D(5, 6));
            test.Add(new Point2D(-2, 1));
            test.Add(new Point2D(-12, -11));
            //test.Min();
            //test.Max()
        }
开发者ID:smihaylovit,项目名称:TelerikAcademy,代码行数:60,代码来源:GenericListTest.cs

示例2: Main

 static void Main()
 {
     GenericList<Decimal> testGenList = new GenericList<decimal>();
     testGenList.Add(125.53M);
     testGenList.Add(123);
     testGenList.Add(100);
     testGenList.Add(1000);
     testGenList.Add(10000);
     Console.WriteLine(testGenList.ToString());
     Console.WriteLine(testGenList.Find(100));
     Console.WriteLine(testGenList.Access(1));
     Console.WriteLine(testGenList.Capacity);
     testGenList.Insert(0, 0);
     testGenList.Insert(5, 3);
     testGenList.Remove(testGenList.Count - 1);
     Console.WriteLine(testGenList.ToString());
     testGenList.Insert(16.16M, testGenList.Count - 1);
     testGenList.Insert(17.17M, testGenList.Count - 1);
     testGenList.Insert(18.18M, testGenList.Count - 1);
     testGenList.Insert(19.19M, testGenList.Count - 1);
     Console.WriteLine(testGenList.ToString());
     Console.WriteLine(testGenList.Max());
     testGenList.Remove(testGenList.Find(testGenList.Max()));
     Console.WriteLine(testGenList.ToString());
     Console.WriteLine(testGenList.Max());
     Console.WriteLine(testGenList.Min());
     testGenList.Remove(0);
     Console.WriteLine(testGenList.Min());
     testGenList.Clear();
     Console.WriteLine(testGenList.ToString());
 }
开发者ID:p0150n,项目名称:TelerikAcademy,代码行数:31,代码来源:GenericListTest.cs

示例3: Main

        static void Main()
        {
            GenericList<int> numbers = new GenericList<int>()
            {
                0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
            };
            Console.WriteLine("Creating a GenericList with the numbers from 1 to 20 \n {0} \n", numbers);

            numbers.Remove(19);
            Console.WriteLine("Removing the 19th element \n {0} \n", numbers);

            numbers.Add(100);
            Console.WriteLine("Adding an element to the end of the GenericList \n {0} \n", numbers);

            numbers.Insert(30, 10);
            Console.WriteLine("Inserting an element on the 10th position \n {0} \n", numbers);

            numbers[3] = 9;
            Console.WriteLine("Changing the value of the 3rd index number \n {0} \n", numbers);

            Console.WriteLine("Trying to find number 4 \n Number Found: {0}, Found At: {1} \n", numbers.Contains(4), numbers.Find(4));
            Console.WriteLine("Trying to find number 80 \n Number Found: {0}, Found At: {1} \n", numbers.Contains(80), numbers.Find(80));
            Console.WriteLine("Min element: {0}, Max element: {1} \n", numbers.Min(), numbers.Max());

            numbers.Clear();
            Console.WriteLine("Cleared GenericList: \n {0} \n", numbers);

            Type type = typeof(GenericList<>);
            VersionAttribute attribute = (VersionAttribute)type.GetCustomAttributes(false).LastOrDefault();
            Console.WriteLine("Version: " + attribute.Version);
        }
开发者ID:Bare7a,项目名称:Software-University,代码行数:31,代码来源:Program.cs

示例4: Main

        static void Main(string[] args)
        {
            Console.WriteLine("GenericList Task\r\n");

            GenericList<string> list = new GenericList<string>("first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eight");
            Console.WriteLine(list);

            list[3] = "fourth changed";
            list.Add("nineth");
            list.Insert(0, "zero");
            list.Remove(5);
            Console.WriteLine("Modified list(indexed access, add, insert, remove):\r\n" + list);

            int found = list.Find("second");
            Console.WriteLine("Search for 'second': index={0}, element={1}", found, list[found]);
            found = list.Find("bla");
            Console.WriteLine("Search for 'bla': index={0}", found);

            Console.WriteLine("Min element: " + list.Min());
            Console.WriteLine("Max element: " + list.Max());

            list.Clear();
            Console.WriteLine("Clearing list: " + list);

            Console.WriteLine("\r\nPress Enter to finish");
            Console.ReadLine();
        }
开发者ID:psotirov,项目名称:TelerikAcademyProjects,代码行数:27,代码来源:GenericListTest.cs

示例5: Main

        public static void Main()
        {
            GenericList<int> test1 = new GenericList<int>(3);
            GenericList<string> test2 = new GenericList<string>(3);
            GenericList<byte> test3 = new GenericList<byte>(3);
            Console.WriteLine("Testing adding");
            test1.Add(2);
            test1.Add(3);
            Console.WriteLine("Testing indexing");
            Console.WriteLine(test1[0]);
            Console.WriteLine(test1[1]);
            Console.WriteLine(test1[0] + test1[1]);
            Console.WriteLine("Testing clear");
            test1.Clear();
            //Console.WriteLine(test1[0]); // this will produce error
            test1.Add(1);
            Console.WriteLine(test1[0]);
            //Console.WriteLine(test1[1]); // this will produce error
            Console.WriteLine("Testing Remove At");
            test1.Add(2);
            test1.Add(3);

            Console.WriteLine(test1[1]);

            test1.RemoveAt(1);
            test1.Add(7);
            Console.WriteLine(test1[1]);

            Console.WriteLine("testing InsertAt");
            test1.Clear();
            test1.Add(1);
            test1.Add(2);
            test1.Add(3);
            test1.Add(4);
            test1.InsertAt(9, 2);
            Console.WriteLine(test1[1]);
            Console.WriteLine(test1[2]);
            Console.WriteLine(test1[3]);

            Console.WriteLine("testing Find");
            Console.WriteLine(test1.Find(0));
            Console.WriteLine(test1.Find(9));
            Console.WriteLine(test1.Find(4));

            Console.WriteLine("testing To String");
            Console.WriteLine(test1);

            Console.WriteLine("Testing min and max");
            Console.WriteLine(test1.Min());
            Console.WriteLine(test1.Max());

            test2.Add("asd");
            test2.Add("angry");
            test2.Add("angraer");
            Console.WriteLine(test2.Min());
            Console.WriteLine(test2.Max());
        }
开发者ID:purlantov,项目名称:TelerikAcademy-4,代码行数:57,代码来源:Testing.cs

示例6: FindTest

        public void FindTest()
        {
            GenericList<int> list = new GenericList<int>();

            for (int i = 0; i < 100; i++)
            {
                list.Add(i);
            }

            Assert.AreEqual(0, list.Find(0));
            Assert.AreEqual(64, list.Find(64));
            Assert.AreEqual(99, list.Find(99));
            Assert.AreEqual(-1, list.Find(100));
        }
开发者ID:Velmond,项目名称:TelerikAcademy-CSharp,代码行数:14,代码来源:GenericListTests.cs

示例7: Main

        static void Main(string[] args)
        {
            GenericList<int> gl = new GenericList<int>(4); // Set the capacity of the list

            // Add some element
            gl.Add(1);
            gl.Add(2);
            gl.Add(3);
            gl.Add(4);

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(gl); // Show the elements
            Console.WriteLine("Count = {0}", gl.Count); // Show the number of added elements
            Console.WriteLine("Capacity = {0}\n", gl.Capacity); // Show the capacity

            gl.InsertAt(0, -1); // Insert element at given position
            gl.InsertAt(3, 256);

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(gl);
            Console.WriteLine("Count = {0}", gl.Count);
            Console.WriteLine("Capacity = {0}\n", gl.Capacity);

            // Add some elements
            gl.Add(1);
            gl.Add(2);
            gl.Add(3);
            gl.Add(4);

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine(gl);
            Console.WriteLine("Count = {0}", gl.Count);
            Console.WriteLine("Capacity = {0}\n", gl.Capacity);

            // Find element with value 1 starting searching from given position
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Index of element with value 1, starting from index 0 is № = {0}", gl.Find(1));
            Console.WriteLine("Index of element with value 1, starting from index 4 is № = {0}", gl.Find(1, 4));

            Console.WriteLine();

            // Find min and max 
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("List's min value = {0}", gl.Min());
            Console.WriteLine("List's max value = {0}", gl.Max());

            Console.WriteLine();
            Console.ResetColor();
        }
开发者ID:nikolay-radkov,项目名称:Telerik-Academy,代码行数:49,代码来源:GenericListTest.cs

示例8: Main

        static void Main(string[] args)
        {
            GenericList<int> test = new GenericList<int>(1);
            test.Add(2);
            test.Add(45);
            test.Add(4);
            test.Add(50);
            test.Add(0);
            test.Add(-1000);

            Console.WriteLine(test);

            test.Remove(4);

            Console.WriteLine(test);

            test.Insert(0, 560);

            Console.WriteLine(test);

            Console.WriteLine(test.Find(123));

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

            test.Clear();

            Console.WriteLine(test);
        }
开发者ID:nikolaZ,项目名称:TelerikAcademy,代码行数:29,代码来源:Program.cs

示例9: Main

        public static void Main(string[] args)
        {
            var l = new GenericList<int>();

            l.Add(3);
            l.Add(4);
            l.Add(235252532);

            Console.WriteLine(l);

            l.Insert(1, 2);
            Console.WriteLine(l);

            Console.WriteLine(l.Find(4));

            l.RemoveAt(1);
            Console.WriteLine(l);

            l.Add(1);
            l.Add(7);
            l.Add(1);
            l.Add(9);
            l.Add(3);
            l.Add(2);
            l.Add(6);
            l.Add(8);
            Console.WriteLine(l);

            Console.WriteLine(l.Min());
            Console.WriteLine(l.Max());
            l.Clear();
            Console.WriteLine(l);
        }
开发者ID:GenoGenov,项目名称:TelerikAcademyAssignments,代码行数:33,代码来源:GenericTest.cs

示例10: Main

    static void Main()
    {
        GenericList<int> list = new GenericList<int>(2);
        list.Add(1);
        list.Add(13);
        list.Add(12);

        Console.WriteLine("Generic list contains: {0}",list);

        Console.WriteLine("Second element of the list is {0}", list[2]);

        Console.WriteLine("Smallest element in the list is {0}", list.Min<int>());

        Console.WriteLine("Biggest element in the list is {0}", list.Max<int>());

        Console.Write("Please enter a value to search: ");

        int valueToSearch = int.Parse(Console.ReadLine());

        Console.WriteLine("Position: {0}", list.Find(valueToSearch));

        list.Clear();

        Console.WriteLine("List Cleared -> {0}", list);
    }
开发者ID:vassil,项目名称:CSharp,代码行数:25,代码来源:TestClass.cs

示例11: Main

        public static void Main()
        {
            Console.WriteLine("> Create new generic list...");
            GenericList<int> list = new GenericList<int>();
            PrintListData(list);

            Console.WriteLine("> Add four items...");
            list = new GenericList<int>(1, 2, 3, 4); // Use the constructor
            PrintListData(list);

            Console.WriteLine("> List is full, add one more item...");
            list.Add(5);
            PrintListData(list);

            Console.WriteLine("> Remove element at index 2...");
            list.RemoveAt(2);
            PrintListData(list);

            Console.WriteLine("> Insert element '3' at index 2...");
            list.InsertAt(3, 2);
            PrintListData(list);

            Console.WriteLine("> Find element '3'...");
            int item = 3;
            int index = list.Find(item);
            Console.WriteLine("Element '{0}' found at index {1}.\n", item, index);

            Console.WriteLine("> Find min and max value...");
            Console.WriteLine("Min: {0}", list.Min());
            Console.WriteLine("Max: {0}\n", list.Max());

            Console.WriteLine(">Clear the list...");
            list.Clear();
            PrintListData(list);
        }
开发者ID:MarKamenov,项目名称:TelerikAcademy,代码行数:35,代码来源:Program.cs

示例12: Main

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

        intList.Add(1);
        intList.Add(2);
        intList.Add(3);
        intList.Add(4);
        intList.Add(5);
        Console.WriteLine("Number of elements: {0}", intList.Count);
        Console.WriteLine(intList);
        intList[4] = 133;
        Console.WriteLine(intList);

        intList.Remove(2);
        Console.WriteLine(intList);

        intList.Insert(0, 4);
        Console.WriteLine(intList);

        Console.WriteLine(intList.Find(133));

        Console.WriteLine(intList.Contains(4));

        Console.WriteLine("Max = " + intList.Max());
        Console.WriteLine("Min = " + intList.Min());

        intList.Clear();
        Console.WriteLine("Elemets in List: " + intList.Count);

        Type type = typeof(GenericList<>);
        object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), false);
        Console.WriteLine("GenericsList's version is {0}", ((VersionAttribute)allAttributes[0]).Version);
    }
开发者ID:GeorgiLambov,项目名称:SoftwareUniversity,代码行数:34,代码来源:GenericListTest.cs

示例13: Main

    static void Main()
    {
        GenericList<int> nums = new GenericList<int>() { 1, 2, 5, 7 };
        Console.WriteLine("All elements: " + nums.ToString());

        Console.WriteLine("Num at index 1: " + nums[1]);
        nums.Remove(0);
        Console.WriteLine("Element at index 0 has been removed");
        Console.WriteLine("Num at index 1: " + nums[1]);
        Console.WriteLine("The index of 5 is: " + nums.Find(5));
        Console.WriteLine("Nums contains 7? " + nums.Contains(7));
        for (int index = 0; index < 50; index++)
        {
            nums.Add(9);
            Console.Write("Element added: " + nums[nums.Count - 1]);
            Console.WriteLine(" Count: " + nums.Count + " Capacity: " + nums.Capacity);
        }
        nums.Insert(14, 0);
        nums.Insert(14, 0);
        nums.Insert(14, 0);
        nums.Insert(20, 20);
        Console.WriteLine(nums);
        Console.WriteLine("Min: " + nums.Min());
        Console.WriteLine("Max: " + nums.Max());

        Console.WriteLine("The version of this class is: " + nums.Version());
    }
开发者ID:shnogeorgiev,项目名称:Software-University-Courses,代码行数:27,代码来源:GenericListDemo.cs

示例14: Main

        public static void Main()
        {
            GenericList<int> myList = new GenericList<int>();

            Console.WriteLine();

            myList.Add(123);
            myList.Add(1293);
            myList.Add(11);
            myList.Add(12314);
            myList.Add(111111);

            Console.WriteLine(myList);
            myList.Remove(2);
            myList.Insert(11, 2);
            myList.Insert(666, 0);
            Console.WriteLine(myList);
            Console.WriteLine(myList.Find(11));
            Console.WriteLine(myList.Contains(11121));
            myList.Add(-100);
            Console.WriteLine(myList.Min());

            Type type = myList.GetType();
            object[] allAttributes =
                type.GetCustomAttributes(false)
                .Where(x => x.GetType() == typeof (VersionAttribute))
                .ToArray();

            foreach (VersionAttribute attr in allAttributes)
            {
                Console.WriteLine(attr.Major + "." + attr.Minor);
            }
        }
开发者ID:Vallerious,项目名称:OOP-Homeworks,代码行数:33,代码来源:GenericListTester.cs

示例15: Main

 static void Main(string[] args)
 {
     var listtt = new List<int>();
     GenericList<int> myList = new GenericList<int>(10);
     //ADD
     myList.Add(1);
     myList.Add(2);
     myList.Add(3);
     Console.WriteLine(myList.ToString());
     Console.WriteLine("Insert element");
     //INSERT AT GIVEN POSITION
     myList.Insert(3, 50);
     myList.Insert(3, 60);
     Console.WriteLine(myList.ToString());
     Console.WriteLine("Find element:");
     //FIND CERTAINT ELEMENT AT WHAT INDEXES EXISTS
     myList.Find(25);
     Console.WriteLine("Remove element:");
     //REMOVE AT CERTAIN INDEX
     myList.Remove(2);
     Console.WriteLine(myList.ToString());
     Console.WriteLine("Find maximum");
     //FIND MAX
     Console.WriteLine(myList.Max());
     Console.WriteLine("Find minimum");
     //FIND MIN
     Console.WriteLine(myList.Max());
     //CLEAR ALL
     Console.WriteLine("Clear all");
     myList.Clear();
     Console.WriteLine(myList.ToString());
 }
开发者ID:AYankova,项目名称:Telerik-Academy-HW,代码行数:32,代码来源:Test.cs


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