using
System;
namespace
ConsoleApplication1
{
class
Program
{
// 1. 声明一个委托 MyDelegate
delegate
void
MyDelegate(
int
a);
static
void
Main(
string
[] args)
{
//2. 定义委托数组
MyDelegate[] fs =
new
MyDelegate[3];
// 3. 建立委托数字,将方法M1,M2,M3放入数组
fs[0] =
new
MyDelegate(M1);
fs[1] =
new
MyDelegate(M2);
fs[2] =
new
MyDelegate(M3);
// 4. 从委托数组调用方法
fs[0](100);
fs[1](200);
fs[2](300);
Console.ReadKey();
}
static
void
M1(
int
a)
{
Console.WriteLine(a);
}
static
void
M2(
int
a)
{
Console.WriteLine(a);
}
static
void
M3(
int
a)
{
Console.WriteLine(a);
}
}
}