C#1到C#4使用委托的几种方式
usingSystem;namespaceDelegateDemo
{classPRogram
{privatedelegateintCacu(stringstr);staticvoidMain(string[] args)
{//1Cacu cacu =newCacu(CacuInstance);
Console.WriteLine(cacu("Hello,Wrold"));//2Cacu cacu1 =newCacu(delegate(stringstr) {returnstr.Length; });
Console.WriteLine(cacu1("Hello,Wrold"));//3Cacu cacu2 =newCacu((str) => {returnstr.Length; });
Console.WriteLine(cacu2("Hello,Wrold"));
}staticintCacuInstance(stringstr)
{returnstr.Length;
}
}
}