首页 > 代码库 > 泛型委托

泛型委托

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

namespace 委托
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 不带返回值的泛型委托
            //Action<int, int> AddAction = new Action<int, int>(StaticAddFunction);
            //if(AddAction!=null)
            //{
            //    AddAction(3, 4);
            //}
            #endregion
            #region 带返回值的泛型委托
            Func<int, int, int> AddFunc = new Func<int, int, int>(StaticAddFunction);
            if (AddFunc != null)
            {
                int nResult = AddFunc(3, 4);
                Console.WriteLine(nResult.ToString());
            }
            #endregion
            Console.ReadKey();

        }
        //static void StaticAddFunction(int a,int b)
        //{
        //    Console.WriteLine("static:" + (a + b).ToString());
        //}

        static int StaticAddFunction(int a, int b)
        {
            return a + b;
        }
    }
}

 

泛型委托