代理( delegate )相当于定义一个以函数形式指向函数的指针。其中代理函数必须与被代理函数有相同的参数表。
例如,如下的例子:
// keyword_delegate.cs
// delegate declaration
delegate void MyDelegate(int i);
class Program
{
public static void Main()
{
TakesADelegate(new MyDelegate(DelegateFunction));
}
public static void TakesADelegate(MyDelegate SomeFunction)
{
SomeFunction(21);
}
public static void DelegateFunction(int i)
{
System.Console.WriteLine("Called by delegate with number: {0}.", i);
}
}
博客介绍了代理(delegate)的概念,它相当于定义一个以函数形式指向函数的指针,且代理函数必须与被代理函数有相同的参数表,并给出了示例。
6万+

被折叠的 条评论
为什么被折叠?



