示例#1
0
        public IntList Filter(IntPredicate p)
        {
            var res = new IntList();

            foreach (var i in this)
            {
                if (p(i))
                {
                    res.Add(i);
                }
            }
            return(res);
        }
示例#2
0
        public IntList greaterThan25(IntPredicate p)
        {
            IntList res = new IntList();

            foreach (int i in this)
            {
                if (p(i))
                {
                    res.Add(i);
                }
            }
            return(res);
        }
示例#3
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();
        }