首页 > Windows开发 > 详细

C# lambda

时间:2016-01-21 06:56:03      阅读:220      评论:0      收藏:0      [点我收藏+]

1. lambda

example 1

            // Create a basic delegate that squares a number
            MyDelegate foo = (x) => x * x;
            Console.WriteLine("The result of foo is: {0}", foo(5));

            // Dynamically change the delegate to something else
            foo = (x) => x * 10;
            Console.WriteLine("The result of bar is: {0}", foo(5));

 example 2

            // Create a delegate that takes multiple arguments
            MyDelegate2 bar = (x, y) =>
            {
                Console.WriteLine("The two-arg lambda: {1}, {0}", x * 10, y);
            };
            bar(25, "Some string");

            // Define an expression delegate
            ExprDelegate baz = (x) => x > 10;
            Console.WriteLine("Calling baz with 5: {0}", baz(5));
            Console.WriteLine("Calling bax with 15: {0}", baz(15));

 

C# lambda

原文:http://www.cnblogs.com/phoenix13suns/p/5147106.html

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