如何将函数用作另一个函数的参数并将其分配给委托
public class myClass
{
public delegate void myDelegate(double x, string s);
//declaration of delegate
public void func(double x, string s)
{
dosomethings...
}
// what is the declaration of the argument 'Function declaration'
public void myFunction('Function declaration' function)
{
myDelegate deFunc;
deFunc = function;
}
}
static void Main(string[] args)
{
myFunction(func);
}
}
Main 是静态的,所以在这种情况下另一个方法也应该是静态的。例如:
public delegate void myDelegate(double x, string s);
//declaration of delegate
public static void func(double x, string s)
{
//dosomethings...
}
// what is the declaration of the argument 'Function declaration'
public static void myFunction(myDelegate function)
{
myDelegate deFunc;
deFunc = function;
}
static void Main(string[] args)
{
myFunction(func);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句