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


C# GenericList.GetIndexByValue方法代码示例

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


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

示例1: Main

    static void Main()
    {
        var list = new GenericList<int>();
        list.Add(1);
        list.Add(2);
        list.Add(3);
        list.Add(4);
        list.Add(3);
        Console.WriteLine(list);

        list[4] = 5;
        Console.WriteLine(list);

        list.Add(-5);
        Console.WriteLine(list);

        Console.WriteLine("list[2] = " + list[2]);
        Console.WriteLine();

        list.RemoveByIndex(list.Count - 1);
        Console.WriteLine(list);
        Console.WriteLine();

        list.Insert(list.Count, 0);
        Console.WriteLine(list);
        Console.WriteLine();

        Console.WriteLine(list.GetIndexByValue(5));
        Console.WriteLine(list.IsContain(5));

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

        list.RemoveAll();
        Console.WriteLine("Empty list" + list);

        Type type = typeof(GenericList<>);
        object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), false);
        Console.WriteLine("GenericsList's version is {0}", ((VersionAttribute)allAttributes[0]).Version);



    }
开发者ID:ScreeM92,项目名称:Software-University,代码行数:44,代码来源:TestGenericList.cs

示例2: Main

        static void Main(string[] args)
        {
            var list = new GenericList<int>();
            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            list.Add(5);

            list[4] = 19;
            Console.WriteLine(list);

            list.Add(-5);
            Console.WriteLine(list);

            Console.WriteLine("list[4] = " + list[4]);

            list.RemoveByIndex(list.Count - 1);
            Console.WriteLine(list);
            Console.WriteLine("{0}",new string('-',60));

            list.Insert(list.Count, 5);
            Console.WriteLine(list);
            Console.WriteLine("{0}", new string('-', 60));

            Console.WriteLine(list.GetIndexByValue(5));
            Console.WriteLine(list.IsContain(8));
            Console.WriteLine("{0}", new string('-', 60));

            Console.WriteLine("Highest = " + list.Max());
            Console.WriteLine("Lowest = " + list.Min());
            Console.WriteLine("{0}", new string('-', 60));

            list.RemoveAll();
            Console.WriteLine("After the List was Deleted = " + list);
            Console.WriteLine("{0}", new string('-', 60));

            Type type = typeof(GenericList<>);
            object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), true);
        }
开发者ID:AlexanderDimitrov,项目名称:OOP,代码行数:40,代码来源:Test.cs

示例3: Main

        public static void Main()
        {
            GenericList<int> newList = new GenericList<int>();
            while (true)
            {
                Console.WriteLine("Enter number for adding to the Generic list OR \"end\":");
                string input = Console.ReadLine();
                if (input == "end")
                {
                    break;
                }

                newList.ListAdd(int.Parse(input));
            }

            while (true)
            {
                Console.WriteLine("Enter index which value you want to get from the Generic list OR \"end\":");
                string input = Console.ReadLine();
                if (input == "end")
                {
                    break;
                }

                int index = int.Parse(input);
                Console.WriteLine("The element with index {0} in the Generic list is {1}.", index, newList.Access(index));
            }

            while (true)
            {
                Console.WriteLine("Enter index which value you want to remove from the Generic list OR \"end\":");
                string input = Console.ReadLine();
                if (input == "end")
                {
                    break;
                }

                int index = int.Parse(input);
                newList.Remove(index);
            }

            while (true)
            {
                Console.WriteLine("Enter index and value which you want to insert at the Generic list OR \"end\":");
                Console.Write("Index: ");
                string input = Console.ReadLine();
                if (input == "end")
                {
                    break;
                }

                int index = int.Parse(input);
                Console.Write("Value:");
                int value = int.Parse(Console.ReadLine());
                newList.Insert(index, value);
            }

            Console.WriteLine("Do you want to clear the Generic list (\"Yes\" ot \"No\"):");
            string answer = Console.ReadLine();
            if (answer == "Yes")
            {
                newList.Clear();
                Console.WriteLine("The array is cleared");
            }
            else
            {
                Console.WriteLine("The array is NOT cleared.");
            }

            while (true)
            {
                Console.WriteLine("Enter value which will be searched at the Generic list OR \"end\":");
                string input = Console.ReadLine();
                if (input == "end")
                {
                    break;
                }

                int value = int.Parse(input);
                Console.WriteLine("The value {0} has index {1} in the Generic list.", value, newList.GetIndexByValue(value));
            }

            if (newList.Length > 0)
            {
                Console.WriteLine("The maximal value in the Generic list is {0}", newList.Max<int>());
                Console.WriteLine("The minimal value in the Generic list is {0}", newList.Min<int>());
            }
            else
            {
                Console.WriteLine("The generic list is empty.");
            }
        }
开发者ID:emilti,项目名称:Telerik-Academy-My-Courses,代码行数:92,代码来源:MainProgram.cs


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