using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace demo1_entrust
{
class Program
{
//委托定义一个实例
delegate int AddDel(int a,int b);
static void Main(string[] args)
{
AddDel del = new AddDel(AddStaticFunc);
Program p = new Program();
del += AddStaticFunc;
int result = del(3,4);
//输出结果(多委托的时候,拿到委托返回值是最后一个指向的执行结果)
Console.WriteLine(result);
Console.ReadKey() ;
}
static int AddStaticFunc(int a ,int b)
{
return a + b;
}
}
}
输出结果: