Lambda表达式和Linq实现数据集的简单筛选并排序

1、Lambda表达式

            List<int> array = new List<int>() { 20, 21, 22, 10, 12, 13, 14, 5, 6, 7, 8, 9 };
            var filtered = (from p in array
                            where p >= 10
                            select p).OrderBy(p => p);
            foreach (int p in filtered)
            {
                Console.WriteLine("Value = {0}", p);
            }


2、Linq

            List<int> array = new List<int>() { 20, 21, 22, 10, 12, 13, 14, 5, 6, 7, 8, 9 };
            foreach (int p in array.Where(p => p >= 10).OrderBy(p => p))
            {
                Console.WriteLine("Value = {0}", p);
            }


展开阅读全文

没有更多推荐了,返回首页