示例#1
0
        static void Main(string[] args)
        {
            IntList list = new IntList();

            for (int i = 0; i < 10; i++)
            {
                list.Add(i);
            }
            list.Add(99);

            list.Act(Console.WriteLine);

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

            var sum = 0;

            //list.Filter(delegate (int i) { sum += i; return true; });
            list.Filter(delegate(int i) { bool check = i % 2 == 0; if (check)
                                          {
                                              sum += i;
                                          }
                                          ; return(check); });
            Console.WriteLine(sum);

            while (true)
            {
                ;
            }
        }
示例#2
0
        public IntList Filter(IntPredicate p)
        {
            IntList res = new IntList();

            foreach (int i in this)
            {
                if (p(i))
                {
                    res.Add(i);
                }
            }
            return(res);
        }