日期:2014-05-17  浏览次数:21020 次

C#的委托类基本实现

?

因为项目需要,对C#进行了一些了解应用,现将收集资料存档,以备查。

?

C#的委托类基本实现

?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Security.Permissions;


namespace ConsoleApplication1
{
    class Program
    {
        //1.定义一个Delegate函数数据结构
        public delegate void GoDelegate();

        //2.定义Delegate将引用的静态方法或引用类实例及该类的实例方法
        public static void MyDelegateFunc()
        {
            //方法实现
        }
        [STAThread]


        public static void Main(string[] args)
        {

            /* 委托处理 start */
            //3.Delegate数据变量指向实例方法
            GoDelegate goDelegate = new GoDelegate(MyDelegateFunc);

            //4.通过Delegate数据变量执行实例方法
            //goDelegate();
            goDelegate.BeginInvoke(null, null);//开始执行houtaiprogram函数
            Console.WriteLine("control ok.");

            /* 委托处理 end */


        }

    }


}

??

?