安全使用委托的-

using System;
using System.Diagnostics;
using System.Text;
using System.Collections;
using System.Collections.Generic;

class Test
{
    public delegate void deltest(string str);
    public static void Callbk(string str)
    {
        Console.WriteLine(str);
    }
    static void Main()
    {
        deltest delt = Callbk;
        delt += Callbk;
        delt("hello");
        delt -= Callbk;
        Console.WriteLine(delt);

        if(delt != null)
        {
            delt -= Callbk;
            Console.WriteLine(delt);
        }
        //if(delt.)
        //delt -= Callbk;

        //delt("world");
    }

}

 

posted @ 2016-11-09 20:04  时空观察者9号  阅读(161)  评论(0编辑  收藏  举报