这个小例子看一下,Lambda 表达式精简干练。。。

namespace ConsoleApplication6
{
delegate int Mydelegate(int i);//定义一个委托
class Program
{
static void Main(string[] args)
{
Func
<int, int> s = item => item * 10;
Console.WriteLine(
"用Lambda表达式");
Console.WriteLine(s(
10));
Console.WriteLine(
"直接调用静态方法");
Console.WriteLine(Mult(
10));
Console.WriteLine(
"使用委托方法");
Mydelegate md1
= new Mydelegate(Mult);
Console.WriteLine(md1(
10));
Console.WriteLine(
"使用匿名方法");
Mydelegate md2
= delegate(int i) { return i * 10; };
Console.WriteLine(md2(
10));
}

public static int Mult(int i)
{
return i * 10;
}
}

 

 posted on 2010-03-29 19:23  zesion  阅读(280)  评论(0编辑  收藏  举报