C# Action 的一般用法

 

最近在看汤姆大叔的JavaScript教程,总结的相当好,可惜自己功力尚浅不能把学到的融会贯通。看过今天大叔发的一篇博文,在js的回调函数中想到了一点关于Action的用法。

发一段简单不能在简单的程序

C# Action
 1 class Program
2 {
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 }
C# Action

运行后

C# Action

将不变的逻辑封装,变化的部分使用委托Action,增加了程序的灵活度!

转载于:https://www.cnblogs.com/songtzu/archive/2012/07/30/2615698.html

相关文章:

  • 2021-07-22
  • 2021-11-18
  • 2021-07-11
  • 2022-12-23
猜你喜欢
  • 2021-12-03
  • 2021-11-18
  • 2021-10-28
  • 2022-12-23
  • 2021-09-23
相关资源
相似解决方案