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


C# GenericList.LastIndexOf方法代码示例

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


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

示例1: Main

        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        public static void Main()
        {
            // so that you can see all the entire printed list of results
            Console.BufferHeight = 200;

            var list = new GenericList<int> { 2, 3, 4, 5, 6, 7, 8, 4, 10 };
            Console.WriteLine("Initial list");
            Console.WriteLine(list);
            list.Version();
            Console.WriteLine();

            // adding an element
            Console.WriteLine("Adding an element");
            Console.WriteLine("Adding element with value 1 to the end of the list:");
            list.Add(1);
            Console.WriteLine(list);
            Console.WriteLine();

            // accessing element by index
            Console.WriteLine("Accessing element by index");
            Console.WriteLine("The element at index {0} is {1}", 2, list[2]);
            Console.WriteLine();

            // finding element index by given value
            Console.WriteLine("Finding element index by given value");
            Console.WriteLine("The first index of {0} is {1}", 4, list.IndexOf(4));
            Console.WriteLine("The last index of {0} is {1}", 4, list.LastIndexOf(4));
            Console.WriteLine();

            // removing element by index
            Console.WriteLine("Removing element by index");
            list.RemoveAt(1);
            Console.WriteLine("Removing the element at index 1, result:");
            Console.WriteLine(list);
            Console.WriteLine();

            // removing element by value
            Console.WriteLine("Removing element by value");
            list.Remove(7);
            Console.WriteLine("Removing the element with value 7, result:");
            Console.WriteLine(list);
            Console.WriteLine();

            // inserting element at given position
            Console.WriteLine("Inserting element at given position");
            list.InsertAt(2, 8);
            Console.WriteLine("Inserted element with value 8 at index 2, result:");
            Console.WriteLine(list);
            Console.WriteLine();

            // checking if the list contains a value
            Console.WriteLine("Checking if the list contains a value");
            Console.WriteLine("Checking if the list contains an element with value 2");
            Console.WriteLine(list.Contains(2));
            Console.WriteLine("Checking if the list contains an element with value 11");
            Console.WriteLine(list.Contains(11));
            Console.WriteLine();

            // finding the minimal and maximal element in the GenericList<T>
            Console.WriteLine("Finding the minimal and maximal element in the GenericList<T>");
            Console.WriteLine("The minimal element in the GenericList is {0}", list.Min());
            Console.WriteLine("The maximal element in the GenericList is {0}", list.Max());
            Console.WriteLine();

            // clearing the list
            Console.WriteLine("Clearing the list");
            Console.WriteLine("GenericList count before clearing: {0}", list.Count);
            list.Clear();
            Console.WriteLine("GenericList count after clearing: {0}", list.Count);
            Console.WriteLine("Displaying the elements in the GenericList: {0}", list);
            Console.WriteLine();

            // adding new elements to the GenericList
            Console.WriteLine("Adding new elements to the GenericList");
            list.Add(6);
            list.Add(4);
            Console.WriteLine("GenericList: {0}", list);
            Console.WriteLine();

            System.Reflection.MemberInfo info = typeof(GenericList<>);
            foreach (object attribute in info.GetCustomAttributes(false))
            {
                Console.WriteLine(attribute);
            }
        }
开发者ID:KatyaMarincheva,项目名称:Object-Oriented-Programming-Course,代码行数:88,代码来源:Program.cs

示例2: Main

        static void Main(string[] args)
        {
            var list = new GenericList<int> { 12, 6, 9, 5, 45, 6, 6, 8, 95, 5 };
            Console.WriteLine("GenericList :");
            Console.WriteLine(list);
            list.Version();
            Console.WriteLine();

            Console.WriteLine("Adding an element");
            list.Add(1);
            Console.WriteLine(list);
            Console.WriteLine();

            Console.WriteLine("Accessing element by index");
            Console.WriteLine("The element at index {0} is {1}", 8, list[8]);
            Console.WriteLine();

            Console.WriteLine("The first index of {0} is {1}", 5, list.IndexOf(5));
            Console.WriteLine("The last index of {0} is {1}", 5, list.LastIndexOf(5));
            Console.WriteLine();

            Console.WriteLine("Removing element by index");
            list.RemoveAt(1);
            Console.WriteLine("Removing the element at index 1, result:");
            Console.WriteLine(list);
            Console.WriteLine();

            Console.WriteLine("Removing element by value");
            list.Remove(45);
            Console.WriteLine("Removing the element with value 45, result:");
            Console.WriteLine(list);
            Console.WriteLine();

            Console.WriteLine("Inserting element at given position");
            list.InsertAt(6, 14);
            Console.WriteLine("Inserted element with value 14 at index 6, result:");
            Console.WriteLine(list);
            Console.WriteLine();

            Console.WriteLine("Checking if the list contains an element with value 6");
            Console.WriteLine(list.Contains(6));
            Console.WriteLine();

            Console.WriteLine("The min element is {0}", list.Min());
            Console.WriteLine("The max element is {0}", list.Max());
            Console.WriteLine();

            Console.WriteLine("List Count before clearing: {0}", list.Count);
            list.Clear();
            Console.WriteLine("List Count after clearing: {0}", list.Count);
            Console.WriteLine("Displaying the elements in the GenericList: {0}", list);
            Console.WriteLine();

            Console.WriteLine("Adding new elements to the GenericList");
            list.Add(6);
            list.Add(5);
            list.Add(89);
            list.Add(12);
            list.Add(5);
            list.Add(99);
            list.Add(65);
            list.Add(456);
            list.Add(44);
            list.Add(8768);
            list.Add(45488);
            list.Add(11);
            Console.WriteLine("GenericList: {0}", list);
            Console.WriteLine();

            System.Reflection.MemberInfo info = typeof(GenericList<>);
            foreach (object attribute in info.GetCustomAttributes(false))
            {
                Console.WriteLine(attribute);
            }
        }
开发者ID:sMustafov,项目名称:Object-Oriented-Programming,代码行数:75,代码来源:Program.cs

示例3: TestGenericListMethods

        /// <summary>
        ///     Tests the generic list methods.
        /// </summary>
        public void TestGenericListMethods()
        {
            var list = new GenericList<int> { 2, 3, 4, 5, 6, 7, 8, 4, 10 };
            Console.WriteLine("Initial list");
            Console.WriteLine(list);
            list.Version();
            Console.WriteLine();

            // adding an element
            Console.WriteLine("Adding an element");
            Console.WriteLine("Adding element with value 1 to the end of the list:");
            list.Add(1);
            Console.WriteLine(list);
            Console.WriteLine();

            // accessing element by index
            Console.WriteLine("Accessing element by index");
            Console.WriteLine("The element at index {0} is {1}", 2, list[2]);
            Console.WriteLine();

            // finding element index by given value
            Console.WriteLine("Finding element index by given value");
            Console.WriteLine("The first index of {0} is {1}", 4, list.IndexOf(4));
            Console.WriteLine("The last index of {0} is {1}", 4, list.LastIndexOf(4));
            Console.WriteLine();

            // removing element by index
            Console.WriteLine("Removing element by index");
            list.RemoveAt(1);
            Console.WriteLine("Removing the element at index 1, result:");
            Console.WriteLine(list);
            Console.WriteLine();

            // removing element by value
            Console.WriteLine("Removing element by value");
            list.Remove(7);
            Console.WriteLine("Removing the element with value 7, result:");
            Console.WriteLine(list);
            Console.WriteLine();

            // inserting element at given position
            Console.WriteLine("Inserting element at given position");
            list.InsertAt(2, 8);
            Console.WriteLine("Inserted element with value 8 at index 2, result:");
            Console.WriteLine(list);
            Console.WriteLine();

            // checking if the list contains a value
            Console.WriteLine("Checking if the list contains a value");
            Console.WriteLine("Checking if the list contains an element with value 2");
            Console.WriteLine(list.Contains(2));
            Console.WriteLine("Checking if the list contains an element with value 11");
            Console.WriteLine(list.Contains(11));
            Console.WriteLine();

            // finding the minimal and maximal element in the GenericList<T>
            Console.WriteLine("Finding the minimal and maximal element in the GenericList<T>");
            Console.WriteLine("The minimal element in the GenericList is {0}", list.Min());
            Console.WriteLine("The maximal element in the GenericList is {0}", list.Max());
            Console.WriteLine();

            // clearing the list
            Console.WriteLine("Clearing the list");
            Console.WriteLine("GenericList count before clearing: {0}", list.Count);
            list.Clear();
            Console.WriteLine("GenericList count after clearing: {0}", list.Count);
            Console.WriteLine("Displaying the elements in the GenericList: {0}", list);
            Console.WriteLine();

            // adding new elements to the GenericList
            Console.WriteLine("Adding new elements to the GenericList");
            list.Add(6);
            list.Add(4);
            Console.WriteLine("GenericList: {0}", list);
            Console.WriteLine();
        }
开发者ID:KatyaMarincheva,项目名称:High-Quality-Code-Course,代码行数:79,代码来源:GenericListFunctionalityTest.cs


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