代碼如下:
//普通委托
DeleteShow ds = new DeleteShow(ShowName);
Console.WriteLine("----------------------");
Console.WriteLine("普通委托----請輸入用戶名:");
string Name = Console.ReadLine();
Console.WriteLine(ds(Name));
Console.WriteLine("----------------------");
//匿名方法委托
DeleteShow ds2 = delegate(string NewName) {
return string.Format("匿名方法委托----輸入的用戶名為:{0}", NewName);
};
Console.WriteLine("----------------------");
Console.WriteLine("請輸入用戶名:");
string WriteName = Console.ReadLine();
Console.WriteLine(ds2(WriteName));
Console.WriteLine("----------------------");
//Lambada委托
DeleteShow ds3 = (LamName) => { return string.Format("Lambada委托----輸入的用戶名為:{0}", LamName); };
Console.WriteLine("----------------------");
Console.WriteLine("請輸入用戶名:");
string WriteLamName = Console.ReadLine();
Console.WriteLine(ds3(WriteLamName));
Console.WriteLine("----------------------");