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


C# GenericList.IndexOf方法代码示例

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


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

示例1: Main

        public static void Main()
        {
            GenericList<int> list = new GenericList<int>(2);
            list.Add(1);
            list.Add(2);
            list.Add(69);
            list.Add(97);
            list.Add(64);
            list.Add(28);
            list.Add(67);
            list.Add(123);

            Console.WriteLine("List: " + list);
            Console.WriteLine("List[6]: " + list[6]);
            Console.WriteLine("Index of 67: " + list.IndexOf(67));
            Console.WriteLine();

            list.RemoveAt(6);
            Console.WriteLine("List: " + list);
            Console.WriteLine("List[6]: " + list[6]);
            Console.WriteLine("Index of 67: " + list.IndexOf(67));
            Console.WriteLine();

            list.InsertAt(5, 72);
            Console.WriteLine("List: " + list);
            Console.WriteLine("Count: " + list.Count);
            Console.WriteLine();
            Console.WriteLine("Max: " + list.Max());
            Console.WriteLine("Min: " + list.Min());
            Console.WriteLine();

            var attr = typeof(GenericList<>).GetCustomAttributes(typeof(Version), false);
            Console.WriteLine("Version: " + attr[0]);
        }
开发者ID:StanisInt,项目名称:SoftUniHomeworks,代码行数:34,代码来源:GenericListProgram.cs

示例2: Main

    public static void Main()
    {
        GenericList<int> test = new GenericList<int>(2);
        test.Add(1);
        test.Add(2);
        test.Add(10);
        test.Add(99);
        test.Add(22);
        test.Add(40);
        test.Add(121);
        test.Add(23);
        Console.WriteLine(test);
        Console.WriteLine(test[3]);
        Console.WriteLine(test.IndexOf(121));
        test.RemoveAt(3);
        Console.WriteLine(test);
        Console.WriteLine(test[3]);
        Console.WriteLine(test.IndexOf(121));
        test.InsertAt(4, 66);
        Console.WriteLine(test);
        Console.WriteLine(test.Count);
        Console.WriteLine("Max: " + test.Max());
        Console.WriteLine("Min: " + test.Min());

        Console.WriteLine();
        //var allAttributes = typeof(GenericList<>).GetCustomAttributes(typeof(VersionAttribute), false);
        //Console.WriteLine("Version: " + allAttributes[0]);
    }
开发者ID:zhanivanov,项目名称:OOP_September_Homeworks,代码行数:28,代码来源:GenericListExample.cs

示例3: Main

        static void Main()
        {

            GenericList<int> integerList = new GenericList<int>();
            Console.WriteLine(integerList.Capacity); // 16
            Console.WriteLine(integerList.Count); // 0

            integerList.Add(1);
            integerList.Add(2);
            integerList.InsertAt(1, 3);
            Console.WriteLine(integerList.Capacity); // 16
            Console.WriteLine(integerList.Count); // 3
            Console.WriteLine(integerList); // {1, 3, 2}
            Console.WriteLine(integerList.IndexOf(1)); // 0
            Console.WriteLine(integerList.Exists(0)); // False
            Console.WriteLine(integerList.Exists(2)); // True

            integerList.RemoveAt(0);
            Console.WriteLine(integerList); // {3, 2}
            Console.WriteLine(integerList.IndexOf(1)); // -1
            Console.WriteLine(GenericList<int>.Min(integerList)); // 2
            Console.WriteLine(GenericList<int>.Max(integerList)); // 3

            integerList.InsertAt(12, 7);
            Console.WriteLine(integerList.Count); // 13
            Console.WriteLine(integerList); // {3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7}

            System.Reflection.MemberInfo info = typeof(GenericList<>);
            foreach (object attribute in info.GetCustomAttributes(false))
            {
                Console.WriteLine(attribute);
            }


        }
开发者ID:asenAce,项目名称:Software_University_Bulgaria,代码行数:35,代码来源:Start.cs

示例4: Main

        static void Main()
        {
            GenericList<int> list = new GenericList<int>(5);
            StringBuilder result = new StringBuilder();
            list.Add(3);
            list.InsertAt(0, 2);
            list.InsertAt(0, 1);
            result.AppendLine(list.ToString());
            result.AppendLine(String.Format("Count: {0}", list.Count));

            result.AppendLine("--REMOVE AT INDEX 1--");
            list.RemoveAt(1);
            result.AppendLine(list.ToString());
            result.AppendLine(String.Format("Count: {0}", list.Count));

            result.AppendLine("     MIN: " + list.Min());
            result.AppendLine("     MAX: " + list.Max());

            result.AppendLine("-----INDEX OF 3-----");
            result.AppendLine(list.IndexOf(3).ToString());
            result.AppendLine("-----INDEX OF 2-----");
            result.AppendLine(list.IndexOf(2).ToString());

            result.AppendLine("-----CLEAR LIST-----");
            list.Clear();
            result.AppendLine(list.ToString());
            result.AppendLine(String.Format("Count: {0}", list.Count));

            Console.WriteLine(result);
        }
开发者ID:RuzmanovDev,项目名称:TelerikAcademy,代码行数:30,代码来源:Test.cs

示例5: Main

        public static void Main()
        {
            /* Solution for Problem 1/Galactic GPS/ */
            Location home = new Location(18.037986, 28.870097, Planet.Earth);
            Console.WriteLine(home);

            Console.WriteLine("----------------------");
            /* Solution for Problem 2/Fraction Calculator/ */
            Fraction fraction1 = new Fraction(22, 7);
            Console.WriteLine(fraction1);
            Fraction fraction2 = new Fraction(40, 4);
            Console.WriteLine(fraction2);
            Fraction result = fraction1 + fraction2;
            Console.WriteLine(result.Numerator);
            Console.WriteLine(result.Denominator);
            Console.WriteLine(result);
            Console.WriteLine(fraction2 - fraction1);

            Console.WriteLine("----------------------");
            /* Solution for Problem 3/Generic List/
             * This sample data is taken from the forum
             */
            GenericList<string> gl = new GenericList<string>(10);
            GenericList<int> gl2 = new GenericList<int>(2);
            gl2.Add(1);
            gl2.Add(2);
            gl2.Add(10);
            gl2.Add(99);
            gl2.Add(22);
            gl2.Add(40);
            gl2.Add(121);
            gl2.Add(23);
            Console.WriteLine(gl2);
            Console.WriteLine(gl2[3]);
            Console.WriteLine(gl2.IndexOf(121));
            gl2.RemoveAt(3);
            Console.WriteLine(gl2);
            Console.WriteLine(gl2[3]);
            Console.WriteLine(gl2.IndexOf(121));
            gl2.InsertAt(4, 66);
            Console.WriteLine(gl2);
            Console.WriteLine(gl2.ListSize);
            Console.WriteLine("Max: " + gl2.Max());
            Console.WriteLine("Min: " + gl2.Min());

            Console.WriteLine("----------------------");
            /* Solution for Problem 4/Generic List Version/ */
            Type type = typeof(GenericList<>);
            object[] versionAttributes = type.GetCustomAttributes(typeof(VersionAttribute), true);
            foreach (VersionAttribute attribute in versionAttributes)
            {
                Console.WriteLine("Version: " + attribute.Major + "." + attribute.Minor);
            }
        }
开发者ID:rvmladenov,项目名称:Soft-Uni,代码行数:54,代码来源:InitProblems.cs

示例6: Main

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

            list.Add(10);
            list.Add(20);
            list.Add(30);

            Console.WriteLine(list); //[10, 20, 30]
            Console.WriteLine("Max: {0}", list.Max()); //30
            Console.WriteLine("Min: {0}", list.Min()); //10

            Console.WriteLine(list[0]); //10
            Console.WriteLine(list[1]); //20

            //Exception:
            //Console.WriteLine(list[-1]);
            //Console.WriteLine(list[3]);

            list[1] = 150;
            Console.WriteLine(list);

            Console.WriteLine(list.Contains(150)); //true
            Console.WriteLine(list.Contains(1000)); //false

            Console.WriteLine(list.IndexOf(30)); //2
            Console.WriteLine(list.IndexOf(1000)); //-1

            list.InsertAtIndex(0, 1000);
            Console.WriteLine(list.ToString()); //[1000, 10, 150, 30]

            list.RemoveAtIndex(0);
            Console.WriteLine(list); //[10, 150, 30]

            //Exception:
            //list.RemoveAtIndex(-1);
            //list.RemoveAtIndex(3);
            //list.InsertAtIndex(-1, 40);
            //list.InsertAtIndex(3, 33);

            Console.WriteLine(list.Pop()); //30
            Console.WriteLine(list); //[10, 150]

            list.Push(-60);
            Console.WriteLine(list); //[10, 150, -60]

            list.Clear();
            Console.WriteLine(list); //[]
        }
开发者ID:nickgenov,项目名称:ObjectOrientedProgramming,代码行数:49,代码来源:GenericListMain.cs

示例7: Main

        static void Main()
        {
            GenericList<int> nums = new GenericList<int>();
            nums.Add(5);
            nums.Add(10);
            nums.Add(50);

            Console.WriteLine(nums.Contains(10)); // output: True
            Console.WriteLine(nums[2]);           // output: 50

            nums[2] = 42;
            Console.WriteLine(nums[2]);           // output: 42

            Console.WriteLine(nums.IndexOf(42));  // output: 2

            Console.WriteLine(nums.Count);        // output: 3

            Console.WriteLine(nums);              // output: [item1, item2...]

            nums.RemoveAt(0);
            Console.WriteLine(nums.Count);        // output: 2

            nums.Clear();
            Console.WriteLine(nums.Count);        // output: 0
        }
开发者ID:msmilkoff,项目名称:OOPHomeworks,代码行数:25,代码来源:MainClass.cs

示例8: Main

        static void Main()
        {
            GenericList<string> glist = new GenericList<string>();
            glist.Add("First");
            glist.Add("Second");
            glist.Add("Third");
            glist.Add("Pesho");
            glist.Add("Gosho");
            glist.Add("Tosho");

            glist.Insert(0, "Purvi Pesho");

            Console.WriteLine(glist);
            Console.WriteLine("Index of \"Second\": {0}", glist.IndexOf("Second"));
            Console.WriteLine("Does contain \"Toshkata\": {0}", glist.Contains("Toshkata"));
            Console.WriteLine("Does contain \"Pesho\": {0}", glist.Contains("Pesho"));

            Console.WriteLine();

            glist.Remove(2);
            glist.Remove(2);

            Console.WriteLine(glist);
            Console.WriteLine("Min Value: {0}", glist.Min());
            Console.WriteLine("Max Value: {0}", glist.Max());

            glist.Clear();

            Console.WriteLine(glist);
        }
开发者ID:hristodobrev,项目名称:Software-University,代码行数:30,代码来源:GenericListManipulation.cs

示例9: Main

        public static void Main()
        {
            GenericList<int> list = new GenericList<int>();
            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            list.Add(5);
            Console.WriteLine("Making a new list:\n " + list);

            Console.WriteLine("Inserting a number 6 at position 2!");
            list.Insert(2, 6);
            Console.WriteLine(list);

            Console.WriteLine("The position of number 3 is {0}!", list.IndexOf(3));

            Console.WriteLine("Remove an element on position 3.");
            list.RemoveAt(3);
            Console.WriteLine(list);

            Console.WriteLine("The MIN element in the list is {0}", list.Min());
            Console.WriteLine("The MAX element in the list is {0}", list.Max());

            list.Clear();

            Console.WriteLine("The list after list.Clear()! \n" + list);

            //Console.WriteLine(list.Min());
        }
开发者ID:tzigy,项目名称:TelerikAcademy,代码行数:29,代码来源:GenericListTest.cs

示例10: Main

        static void Main()
        {
            GenericList<string> names = new GenericList<string>();
            names.ShowVersion();

            names.Add("Gosho");
            names.Add("Pesho");
            names.Add("Misho");
            names.Add("Tisho");
            names.Add("Nashmat");
            names.Add("Onufri");
            names.Add("Gencho");

            names.Insert("Tyanko", 2);
            names.Remove(1);
            //names.Clear();

            names.Add("Asen");
            names.Add("Zaro");

            Console.WriteLine("All elements: " + names);
            Console.WriteLine("Max element: " + names.Max());
            Console.WriteLine("Min element: " + names.Min());

            string search = "Onufri";
            Console.WriteLine("Elements contain {0}: {1}", search, names.Contains(search));
            Console.WriteLine("Index of {0}: {1}", search, names.IndexOf(search));
        }
开发者ID:AsenTahchiyski,项目名称:SoftUni,代码行数:28,代码来源:Program.cs

示例11: Main

 static void Main()
 {
     var newList = new GenericList<int>();
     for (int i = 0; i < 5; i++)
     {
         newList.Add(i);
     }
     newList.Remove(3);
     newList.Insert(3, 3);
     Console.WriteLine("For each");
     foreach (var item in newList)
     {
         Console.WriteLine(item);
     }
     Console.WriteLine();
     Console.WriteLine("Index of");
     Console.WriteLine(newList.IndexOf(2));
     Console.WriteLine();
     Console.WriteLine("ToString");
     Console.WriteLine(newList);
     Console.WriteLine();
     Console.WriteLine("Min");
     Console.WriteLine(newList.Min());
     Console.WriteLine();
     Console.WriteLine("Max");
     Console.WriteLine(newList.Max());
     newList.Clear();
     Console.WriteLine("After clear");
     Console.WriteLine(newList);
     Console.WriteLine("Test whatever you want!");
 }
开发者ID:radenkovn,项目名称:Telerik-Homework,代码行数:31,代码来源:GenericClassTest.cs

示例12: Main

 public static void Main()
 {
     GenericList<int> a = new GenericList<int>();
     a.Add(15);
     a.Add(20);
     a.Add(30);
     a.Add(40);
     a.Add(55);
     a.Add(60);
     a.Add(70);
     a.Add(100);
     a.Add(100);
     Console.WriteLine(a.Capacity);
     a.Add(15);
     a[2] = 500;
     Console.WriteLine(a);
     Console.WriteLine(a.IndexOf(30));
     Console.WriteLine(a.Contains(500));
     a.InsertAt(10, 59);
     a.InsertAt(11, 59);
     a.InsertAt(12, 59);
     a.InsertAt(13, 59);
     a.InsertAt(14, 59);
     a.InsertAt(15, 59);
     a.InsertAt(16, 59);
     Console.WriteLine(a);
     Console.WriteLine(a.Capacity);
     Console.WriteLine(a.IsEmpty);
     Console.WriteLine(a.Min());
     Console.WriteLine(a.Max());
     a.Clear();
 }
开发者ID:vdonchev,项目名称:OOPOtherTypesHW,代码行数:32,代码来源:Test.cs

示例13: Main

        static void Main()
        {
            GenericList<int> l = new GenericList<int>(1);

            l.Add(1);
            l.Add(2);
            l.Add(3);
            l.Add(4);
            l.Add(5);
            l.Add(-1);

            Console.WriteLine(l);

            l.RemoveAt(5);

            Console.WriteLine(l);

            l.InsertAt(0, -3);

            Console.WriteLine(l);

            Console.WriteLine(l.IndexOf(-3));

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

            l.Clear();

            Console.WriteLine(l);
        }
开发者ID:neofitov,项目名称:TelerikAcademyHomeworks,代码行数:30,代码来源:Test.cs

示例14: Main

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

            intList.AddRange(Enumerable.Range(1, 30).ToArray());

            Console.WriteLine("Number of elements: {0}", intList.Count);
            Console.WriteLine(intList);

            Console.WriteLine($"List contains 7: {intList.Contains(7)}");
            Console.WriteLine($"Index of 12: {intList.IndexOf(12)}");

            Console.WriteLine();

            var stringList = new GenericList<string>
            {
                "C#",
                "Java",
                "PHP",
                "SQL"
            };

            Console.WriteLine($"Number of elements: {stringList.Count}");
            Console.WriteLine(stringList);

            Console.WriteLine($"List contains \"Java\": {stringList.Contains("Java")}");
        }
开发者ID:HouseBreaker,项目名称:OOP,代码行数:27,代码来源:GenericListMain.cs

示例15: Main

        public static void Main()
        {
            Console.Title = "Problem 3.	Generic ";

            GenericList<int> numbers = new GenericList<int>();
            numbers.Add(5);
            numbers.Add(50);
            numbers.Add(500);
            numbers.Add(1000);

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

            Console.WriteLine(numbers.GetAtIndex(1));
            numbers.Insert(1, 25);
            Console.WriteLine(numbers.IndexOf(50));
            Console.WriteLine(numbers.Contains(5));
            numbers.Remove(5);
            Console.WriteLine(numbers);
            numbers.Clear();
            Console.WriteLine(numbers);

            Console.WriteLine();
            Console.WriteLine("Problem 4.	Generic List Version");
            System.Reflection.MemberInfo info = typeof(GenericList<>);
            foreach (object attribute in info.GetCustomAttributes(false))
            {
                Console.WriteLine(attribute);
            }
        }
开发者ID:Nezhdetov,项目名称:Software-University,代码行数:30,代码来源:GenericListMain.cs


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