由 lambda 分配给委托

Lambdas 可用于创建分配给委托的匿名方法:

Func<int,int> addOne = x => x+1;

请注意,以这种方式创建变量时需要显式声明类型:

var addOne = x => x+1; // Does not work