I have the following:
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));
}
}
Is the method writeOutput in the above required? Can the following be re-written, without writeoutput, to output the same as the above?
Can the line Console.WriteLine("x^2 = {0}", new myDelegate(x => x*x)); be amended so that 3 is fed into the function?
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();
}
}