c# 中的 map-reduce-filter

时间:2017-08-18 19:22:54   收藏:0   阅读:249

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/

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!