C#中使用委托的3种方式代码示例
usingSystem;
namespaceDelegateDemo
{
classProgram
{
privatedelegateintCacu(stringstr);
staticvoidMain(string[]args)
{
//1
Cacucacu=newCacu(CacuInstance);
Console.WriteLine(cacu("Hello,Wrold"));
//2
Cacucacu1=newCacu(delegate(stringstr){returnstr.Length;});
Console.WriteLine(cacu1("Hello,Wrold"));
//3
Cacucacu2=newCacu((str)=>{returnstr.Length;});
Console.WriteLine(cacu2("Hello,Wrold"));
}
staticintCacuInstance(stringstr)
{
returnstr.Length;
}
}
}热门推荐
10 商业装修开工祝福语简短
11 新人新婚敬酒祝福语简短
12 收到乔迁礼物祝福语简短
13 如何问候生日祝福语简短
14 送媳妇首饰祝福语简短
15 结婚婚宴圆满祝福语简短
16 疫情加油蛋糕祝福语简短
17 服装超市开业祝福语简短
18 妹妹生日宴祝福语简短