Could someone tell me how does it work? I would be grateful. Dunno how to debug this.
using System;
class Prg
{
private static Func<double, Func<double, double>> Add(int c)
{
return x => y => x + y++ + (c *= 2);
}
public static void Main(string[] args)
{
int a = 1;
int b = 100;
var F = Add(2);
var G = F(a);
G(b);
Console.WriteLine(G(b));
}
}
EDIT: I have got another one if you want to enjoy our C# exam.. Here is the code.
delegate int F();
class Prg { int a = 10;
public F Adder(int x) {
int i = x;
return delegate {
return a += i++; };
}
static void Main() {
Prg p = new Prg();
F f = p.Adder(5);
p.Adder(10);
f();
System.Console.Write(f());
} }