委托:
是一种引用类型,把方法像变量赋值一样赋值给委托对象,委托对象拥有方法一样的行为。
声明委托:
[访问修饰符] delegate 返回值类型 委托名(参数列表);
委托在类之外声明
把方法赋值给委托,要与委托有相同的签名(相同的返回值与参数的类型,参数个数,参数顺序)
public delegate int abc(int a,int b);
class Program
{
public int one (int a,int b)//实力方法
{
int num1;
num1 = a * b;
Console.WriteLine(num1);
return num1;
}
static void Main(string[] args)
{
Program main=new Program();
abc z = main.one; //对象的方法赋值给委托对象 委托作为类型
Console.WriteLine(z