Beispiel #1
0
        static void Main(string[] args)
        {
            /*// Explicity loop
             * var enumerator = Naturals().GetEnumerator();
             * Console.WriteLine(enumerator.Current);
             * while (enumerator.MoveNext())
             * {
             *  Console.WriteLine(enumerator.Current);
             *  Console.ReadLine();
             * }
             * /*var naturals = Naturals();
             * foreach (var item in naturals)
             * {
             *  Console.WriteLine(item);
             * //  Console.ReadKey();
             * }*/
            var  backPack = new LimitedList <string>(10);
            bool added;
            int  count = 0;

            do
            {
                count += 1;
                added  = backPack.Add($"item {count}");
            } while (added);

            /*backPack.Add(4);
            *  backPack.Add(2);
            *  backPack.Add(6);
            *  backPack.Add(8);
            *  backPack.Add(0);*/

            foreach (var item in backPack)
            {
                Console.WriteLine(item);
            }

            Console.ReadKey();

            count = 0;
            string remove = null;

            foreach (var item in backPack)
            {
                if (count == 3)
                {
                    remove = item;
                }
                count += 1;
            }
            backPack.Remove(remove);

            foreach (var item in backPack)
            {
                Console.WriteLine(item);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            // Explicit loop
            //var enumerator = Naturals().GetEnumerator();
            //Console.WriteLine(enumerator.Current);
            //while (enumerator.MoveNext()) {
            //    Console.WriteLine(enumerator.Current);
            //    Console.ReadLine();
            //}

            // LimitedList
            var backPack = new LimitedList <string>(10);

            bool added;
            int  count = 0;

            do
            {
                count += 1;
                added  = backPack.Add($"item {count}");
            } while (added);
            Inventory(backPack);
            Console.ReadKey(true);

            count = 0;
            string remove = null;

            foreach (var item in backPack)
            {
                if (count == 3)
                {
                    remove = item;
                }
                count += 1;
            }
            backPack.Remove(remove);
            Inventory(backPack);
        }