委托简单实例

来源:互联网 发布:知乎成都最好的研究所 编辑:程序博客网 时间:2024/05/20 12:48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;


namespace yufademo
{
    class Program
    {
        delegate void getstring(string name);//定义委托
        static void Main(string[] args)
        {
            getstring g = new getstring(M2);//委托关联方法
            g("song");//用委托的形式来执行方法
            Console.Read();
            
        }
        static void M2(string s1)//定义一个方法
        {
            Console.WriteLine(s1);
        }
    }
  
   
    
   
   
}
原创粉丝点击