委派函式:
delegate void TestDelegate(string str);
程式碼:
static void Main(string[] args) {
TestDelegate t1 = (string s1) => { Console.WriteLine("print from s1:" + s1); };
TestDelegate t2 = (string s2) => { Console.WriteLine("print from s2:" + s2); };
t1 += t1 + t2 + t1;
t1("Hello");
t1.Invoke("Hello world");
Console.ReadKey();
}
結果:
更多內容可以參考:
Lambda 運算式 (C# 程式設計手冊)

沒有留言:
張貼留言