面向对象:委托

namespace ConsoleApplication5
{
    public delegate int mydelegate(int a,int b);//定义委托

    public class Class1
    {
        public int jiafa(int a, int b)
        {
            return a + b;
        }
    }
}
namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            mydelegate a = new Class1().jiafa;
            Console.WriteLine(a(1,2));//结果为3
            Console.ReadLine();
        }
    }
}

委托定义在namespace内,class外。

public degegate int mydelegate (int a,int b)

 

mydelegate = b,c,d;

b=new......XXX();

c=new......XXX();

d=new......XXX();

 

d=b+c;//先算b再算c最后得到c的返回值

d=c+b;//先算c再算b最后得到b的返回值

posted @ 2015-05-28 15:43  Yusarin  阅读(160)  评论(0编辑  收藏  举报