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 杨奕老师祝福语简短