匿名委托与λ表达式
delegate string DelegateTest(string val);
delegate string DelegateTest2(string val,int val2);
static void Main(string[] args)
{
string mid = ",middle part,";
DelegateTest anonDel = delegate(string param)
{
param += mid;
param += "and this was added to the string.";
return param;
};
DelegateTest2 anonDel2 = (param,param2) =>
{
param += mid;
param += "and this was added to the string.";
param += param2.ToString();
return param;
};
DelegateTest anonDel3 = param => param += "and this was added to the string.";
Console.WriteLine(anonDel("Start of string"));
Console.WriteLine(anonDel2("Start of string",2));
Console.WriteLine(anonDel3("Start of string"));
Console.Read();
}
浙公网安备 33010602011771号