一、【action<>】指定那些只有输入参数,没有返回值的委托

用了Action之后呢:

就是相当于省去了定义委托的步骤了。

演示代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EventDemo
{
    class Program
    {
        public delegate void myDelegate(string str);  
        public static void HellowChinese(string strChinese)  
        {  
            Console.WriteLine("Good morning," + strChinese);  
            Console.ReadLine();  
        }  

        static void Main(string[] args)
        {
            //Delegate的代码
            myDelegate d = new myDelegate(HellowChinese);
            d("Mr wang");

            //用了Action之后呢
            Action<string> action = HellowChinese;
            action("Spring.");

            Console.ReadLine();
        }
    }
}
View Code

相关文章: