using
System;
namespace use_delegate
{
/**//// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
//第一步:声明委托(委托的参数类型和返回值类型必须和委托的目标函数一致)
public delegate int myDelegate(double D);
//第二步:构建委托的目标函数
public int returnInt(double D)
{
return Convert.ToInt32(D);
}
//第三步:委托的使用
public void amethod()
{
//1、创建委托实例(函数指针)
myDelegate aDelegate=new myDelegate(returnInt);
//2、使用委托(通过函数指针调用函数)
Console.WriteLine(aDelegate(123.11125));
}
/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Class1 c1=new Class1();
c1.amethod();
}
}
}
namespace use_delegate
{
/**//// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
//第一步:声明委托(委托的参数类型和返回值类型必须和委托的目标函数一致)
public delegate int myDelegate(double D);
//第二步:构建委托的目标函数
public int returnInt(double D)
{
return Convert.ToInt32(D);
}
//第三步:委托的使用
public void amethod()
{
//1、创建委托实例(函数指针)
myDelegate aDelegate=new myDelegate(returnInt);
//2、使用委托(通过函数指针调用函数)
Console.WriteLine(aDelegate(123.11125));
}
/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Class1 c1=new Class1();
c1.amethod();
}
}
}
完整源代码下载: use_delegate.rar