C# Action
C# Action 的一般用法
最近在看湯姆大叔的JavaScript教程,總結的相當好,可惜自己功力尚淺不能把學到的融會貫通。看過今天大叔發的一篇博文,在js的回調函數中想到了一點關于Action的用法。
發一段簡單不能在簡單的程序
1 class Program2 {
3 static void Main(string[] args)
4 {
5 string myName = "CC";
6 GetFullInfo(myName,s => Console.WriteLine(s));
7
8 Console.ReadLine();
9
10 }
11
12
13 static void GetFullInfo(string yourname, Action<string> action)
14 {
15 string firstStr = "Welcome to cnblogs ";
16 action(firstStr + yourname);
17 }
18 }
運行后
將不變的邏輯封裝,變化的部分使用委托Action,增加了程序的靈活度!
轉載于:https://www.cnblogs.com/songtzu/archive/2012/07/30/2615698.html
總結
- 上一篇: 草图几何约束求解
- 下一篇: rational rose 逆向工程