什么叫匿名方法

匿名方法是指将一段代码块作为委托参数传递给另外一个方法中。

匿名方法能访问方法中的变量和类中的成员。

使用匿名方法,则不必创建当独的方法,因此减少了实例化委托所需的编码开销。

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
public class Program
{
public delegate string gettypername(string name);
static void Main(string[] args)
{
string aaaa = "11";
gettypername name
= delegate(string t)
{
t
+= "最新的";
return t;

};
Console.WriteLine(name);
Console.ReadLine();

}







}
}

 

posted @ 2010-08-12 09:19  二锅头  阅读(647)  评论(0)    收藏  举报