簡單委託示例

 

   public delegate void Del(string message);

        static void Main(string[] args)
        {
            #region 調用委託
            Del handler = DelegateMethod;
            handler("Hello World");
            #endregion

            #region 委託的異步回調
            Program TestCallBack = new Program();
            TestCallBack.MethodWithCallback(1, 2, handler);
            #endregion

        }

        #region 一般調用委託的方法
        public static void DelegateMethod(string message)
        {
            System.Console.WriteLine(message);
        }
        #endregion

        #region 委託的異步回調的方法
        public void MethodWithCallback(int param1, int param2, Del callback)
        {
            callback("The number is: " + (param1 + param2).ToString());
        }
        #endregion

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章