예제 #1
0
        static void Main()
        {
            GenList <int> listOne = new GenList <int>();

            listOne.Add(5);
            listOne.Add(180);
            listOne.Add(-150);
            for (int i = 0; i < 20; i++)
            {
                listOne.Add(i);
            }

            Console.WriteLine(string.Join(", ", listOne));
            Console.WriteLine(listOne.Max());
            Console.WriteLine(listOne.Min());
            Console.WriteLine(listOne.IndexOf(-150));
            Console.WriteLine(listOne.IndexOf(-250));
            listOne.Remove(180);
            Console.WriteLine();
            Console.WriteLine(string.Join(", ", listOne));
            listOne.RemoveAt(5);
            Console.WriteLine();
            Console.WriteLine(string.Join(", ", listOne));
            listOne.Insert(10, 555555);
            Console.WriteLine();
            Console.WriteLine(string.Join(", ", listOne));
            //listOne.Clear();
            //Console.WriteLine();
            //Console.WriteLine(string.Join(", ", listOne)); uncomment to clear the list
            Console.WriteLine();
            Console.WriteLine(listOne.Contains(800));
            Console.WriteLine();

            Console.WriteLine("listOne[3] = {0}", listOne[3]);

            Console.WriteLine("To String:");
            Console.WriteLine(listOne.ToString());
        }
예제 #2
0
        static void Main(string[] args)
        {
            GenList <int> nmbrs = new GenList <int>();

            nmbrs.Add(6);
            nmbrs.Add(8);
            nmbrs.Add(10);
            nmbrs.Add(9);
            nmbrs.Add(1);

            Console.WriteLine("Initial List");
            foreach (var nmbr in nmbrs)
            {
                Console.Write($"{(int)nmbr} ");
            }

            Console.WriteLine($"\nIs Element 9 removed: {nmbrs.Remove(9)}");
            Console.WriteLine($"Is Element 7 removed: {nmbrs.Remove(7)}");

            Console.WriteLine("List after removing 9 and 7:");
            foreach (var nmbr in nmbrs)
            {
                Console.Write($"{(int)nmbr} ");
            }

            nmbrs.RemoveAt(0);

            Console.WriteLine("\nList after removing first element");
            foreach (var nmbr in nmbrs)
            {
                Console.Write($"{(int)nmbr} ");
            }

            nmbrs.RemoveAt(-1);

            Console.WriteLine($"First occurence of element less than 5: {nmbrs.Find(x => x < 5)}");

            Console.WriteLine($"Default value for returning in Find for this type:{nmbrs.Find(x => x < -1)} ");

            Console.WriteLine($"Index of first occurence of element less than 5: {nmbrs.FindIndex(x => x < 5)}");

            Console.WriteLine($"Index of first occurence of element less than -1: {nmbrs.FindIndex(x => x < -1)}");

            nmbrs.Insert(3, 12);
            nmbrs.Insert(1, 50);
            Console.WriteLine("List after inserting element 12 and 50");
            foreach (var nmbr in nmbrs)
            {
                Console.Write($"{(int)nmbr} ");
            }

            nmbrs.Insert(-3, 10);

            Console.WriteLine($"Number of removed elements {nmbrs.RemoveAll()}");

            Console.WriteLine("\nList after removing all elements");
            foreach (var nmbr in nmbrs)
            {
                Console.Write($"{(int)nmbr} ");
            }

            Console.ReadLine();
        }