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