C#中委托的问题,高手请进。。。

来源:百度知道 编辑:UC知道 时间:2024/06/17 15:54:08
using System;

delegate void eatx(string food);
class s
{
static void Main()
{
eatx k = null ;
k += delegate(string food)( Console.WriteLine("张三" + food); );

}
}

教程中是这样写的没有错,他是在develop中写的,可是我在VS2005当中这样写不能运行,帮我看看要怎么改?
Main中还少有这句:

k("西瓜");

k += delegate(string food)( Console.WriteLine("张三" + food); );
改成

k += delegate(string food){ Console.WriteLine("张三" + food); };

注意大括号 和 小括号 的区分

k += delegate(Console.WriteLine("张三" + food));

delegate void eatx(string food);
class s
{
static void Main()
{
eatx k = null;
k += delegate(string food) { Console.WriteLine("张三" + food); };

}
}