C#实现的几种委托方式介绍
//普通委托
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("----------------------");
上一篇:使用.Net Core编写命令行工具(CLI)的方法
栏 目:.NET代码
本文标题:C#实现的几种委托方式介绍
本文地址:http://www.codeinn.net/misctech/80099.html