码迷,mamicode.com
首页 > Windows程序 > 详细

c# 中的 map-reduce-filter

时间:2017-08-18 20:12:09      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:func   static   console   lis   int   mapred   lin   class   pre   

js中的es6 中提出 map  reduce filter 等方法;

那么我们在c#中似乎没看到呢,真的吗? are you kiding me?

 先看map

      static IEnumerable<TResult> Map<T,TResult>(Func<T, TResult> func,IEnumerable<T> list)
        {
            foreach(var i in list)
            {
                yield return func(i);
            }
        }



        static void Main(string[] args)
        {
            var testList = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            var mapResult = Map<int, int>(x => x + 2, testList).ToList<int>();

            foreach(var i in mapResult)
            {
                Console.WriteLine(i);
            }

            //然而,在我们的额linq 早就有了该方法;那就是我们的map
            var result = testList.Select(obj => obj + 2).ToList<int>();

            Console.ReadLine();

 

 

 

 

回家健身了,明天继续搞;

 

 

 

 

 

好文 推荐:http://www.justinshield.com/2011/06/mapreduce-in-c/

c# 中的 map-reduce-filter

标签:func   static   console   lis   int   mapred   lin   class   pre   

原文地址:http://www.cnblogs.com/mc67/p/7391007.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!