C#中使用委托的3种方式代码示例
摘要:usingSystem;namespaceDelegateDemo{classProgram{privatedelegateintCacu(...
using System; namespace DelegateDemo { class Program { private delegate int Cacu(string str); static void Main(string[] args) { //1 Cacu cacu = new Cacu(CacuInstance); Console.WriteLine(cacu("Hello,Wrold")); //2 Cacu cacu1 = new Cacu(delegate(string str) { return str.Length; }); Console.WriteLine(cacu1("Hello,Wrold")); //3 Cacu cacu2 = new Cacu((str) => { return str.Length; }); Console.WriteLine(cacu2("Hello,Wrold")); } static int CacuInstance(string str) { return str.Length; } } }
【C#中使用委托的3种方式代码示例】相关文章:
★ 基于使用BeginInvoke,EndInvoke异步调用委托的实现代码
上一篇:
C#实现在匿名方法中捕获外部变量的方法