日期:2014-05-17  浏览次数:20698 次

我想知道这段代码不用拉姆达和匿名委托怎么写?
对委托的理解还是不太深,用的太少,请指教,RT.

            List<int> iList = new List<int> { 1, 1, 3, 3, 3, 4, 4, 2, 2, 6, 6, 5, 7, 9, 8 };
            //获得满足条件个数
            int count = iList.Count<int>(p => p > 7);

            //使用匿名委托
            //int count1 = iList.Count<int>
            //    (
            //        delegate(int i)
            //        {
            //            if (i > 7)
            //            {
            //                return true;
            //            }
            //            else
            //            {
            //                return false;
            //            };
            //        }
            //    );
linq 委托

------解决方案--------------------
lambda经编译器展开后如下:

            int count = iList.Count<Int32>(new Func<Int32,Boolean>(Count7));
        }
        static Boolean Count7(Int32 item)
        {
            if (item > 7)
            {
                return true;
            }
            return false;
        }