Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            IntList xs = new IntList();

            xs.Add(11); xs.Add(20); xs.Add(31); xs.Add(40);
            xs.Add(51); xs.Add(71); xs.Add(80); xs.Add(91);

            xs.Act(Console.WriteLine);
            Console.WriteLine(" ");

            Console.WriteLine("Elements divisible by 2. ");
            xs.Filter(delegate(int x) { return(x % 2 == 0); }).Act(Console.WriteLine);

            Console.WriteLine(" ");
            Console.WriteLine("Elements greater than 25. ");
            xs.Filter(y => y > 25).Act(Console.WriteLine);

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var xs = new IntList(1, 2, 3, 4, 500, 100);

            #region IntList

            Console.WriteLine("\n------------ IntList ------------");

            Console.WriteLine("\nPrint all elements");
            xs.Act(Console.WriteLine);
            Console.WriteLine("\nCustom print all elements");
            xs.Act(CustomWriteLine);

            Console.WriteLine("\nPrint all even elements");
            xs.Filter(x => x % 2 == 0).Act(Console.WriteLine);

            Console.WriteLine("\nPrint all even elements that are greater than or equal to 25");
            xs.Filter(x => x >= 25).Act(Console.WriteLine);

            xs.Act(AddElements);
            Console.WriteLine($"\nSum of {xs.ToString<int>()} is {_count}");

            #endregion

            #region Generic List

            Console.WriteLine("\n------------ Generic List ------------");

            var stringList = new MyList <string>("Sara", "Jonh", "Maria");

            Console.WriteLine("\nPrint all elements");
            stringList.Act(Console.WriteLine);

            Console.WriteLine("\nCustom print all elements");
            stringList.Act(CustomWriteLine);

            Console.WriteLine("\nPrint all elements with more than 4 leters");
            stringList.Filter(x => x.Length > 4).Act(Console.WriteLine);

            #endregion

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        public static void Main(String[] args)
        {
            var xs = new IntList {
                1, 122, 3, 4, 5
            };

            xs.Act(Console.WriteLine);

            Console.WriteLine("Print only even numbers:");
            xs.Filter(delegate(int x) { return(x % 2 == 0); }).Act(Console.WriteLine);

            Console.WriteLine("Using anonymous methods: (x >= 25) ");
            xs.Act(delegate(int x) { if (x >= 25)
                                     {
                                         Console.WriteLine(x);
                                     }
                   });
            // xs.Filter(delegate (int x) { return x >= 25; }).Act(Console.WriteLine);

            Console.WriteLine("Computing sum: ");
            int sum = 0;

            xs.Act(delegate(int x) { sum += x; });
            Console.WriteLine(sum);

            //Generic
            Console.WriteLine("Generics");
            var gs = new MyList <int> {
                1, 122, 3, 4, 5
            };

            gs.Act(Console.WriteLine);

            Console.WriteLine("Print only even numbers:");
            gs.Filter(delegate(int x) { return(x % 2 == 0); }).Act(Console.WriteLine);

            Console.WriteLine("Using anonymous methods: (x >= 25) ");
            gs.Act(delegate(int x) { if (x >= 25)
                                     {
                                         Console.WriteLine(x);
                                     }
                   });
            // gs.Filter(delegate (int x) { return x >= 25; }).Act(Console.WriteLine);

            Console.WriteLine("Computing sum: ");
            int sumg = 0;

            gs.Act(delegate(int x) { sumg += x; });
            Console.WriteLine(sum);
            Console.ReadKey();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            IntList xs  = new IntList(2, 4, 7, 9, 13);
            IntList xs1 = new IntList(25, 30, 1, 35, 0);

            xs.Act(Console.WriteLine);
            xs.Filter(delegate(int x) { return(x % 2 == 0); }).Act(Console.WriteLine);
            xs1.Filter(delegate(int x) { return(x > 25); }).Act(Console.WriteLine);
            int sum = 0;

            xs1.Act(p => sum += p);
            Console.WriteLine(sum);
            Console.ReadKey();
        }