委托简单实例
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);
}
}
}
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);
}
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.