首页 > Windows开发 > 详细

c# 中的 map-reduce-filter

时间:2017-08-18 19:22:54      阅读:249      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!