Beispiel #1
0
    //声明一个将来要调用的普通方法,注意必须跟委托的参数和返回值签名相同
    //private void GoTest()
    //{
    //    Debug.Log("111");
    //}

    private void Start()
    {
        //把普通方法赋值给委托变量
        //myDelegateTest = GoTest;
        myDelegateTest = () =>
        {
            Debug.Log("111");
        };

        //调用存有方法的委托变量,也就等同与调用了前面定义的那个普通方法
        myDelegateTest();
    }
Beispiel #2
0
        void Test1()
        {
            var dlg = new TheDelegate(MyStaticDelegate);

            dlg(1, new Exception("STATIC"));

            var inst = new TestDelegate();

            dlg = new TheDelegate(inst.MyVirtualDelegate);
            dlg(2, new Exception("VIRTUAL"));

            var inst2 = new MyDelegateClass <long, object, bool>();

            dlg = new TheDelegate(inst2.GenericDelegate);
            bool b3 = dlg(3, new Exception("INSTANCE GENERIC"));

            dlg = new TheDelegate(StaticGenericDelegate <long, object>);
            dlg(4, new Exception("STATIC GENERIC"));

            dlg = new TheDelegate(this.InstanceGenericDelegate <long, object>);
            dlg(5, new Exception("INSTANCE GENERIC"));
        }