我有以下内容:
class Program {
delegate int myDelegate(int x);
static void Main(string[] args) {
Program p = new Program();
Console.WriteLine(p.writeOutput(3, new myDelegate(x => x*x)));
Console.WriteLine("press [enter] to exit");
Console.ReadLine();
}
private string writeOutput(int x, myDelegate del) {
return string.Format("{0}^2 = {1}",x, del(x));
}
}
是否需要上述方法writeOutput
?可以在没有 , 的情况下重写以下内容writeoutput
以输出与上述相同的内容吗?
可以修改该行Console.WriteLine("x^2 = {0}", new myDelegate(x => x*x));
以便将 3 输入到函数中吗?
class Program {
delegate int myDelegate(int x);
static void Main(string[] args) {
Program p = new Program();
Console.WriteLine("x^2 = {0}", new myDelegate(x => x*x));
Console.WriteLine("press [enter] to exit");
Console.ReadLine();
}
}