Back to questions
JuniorTheoryCommon
What does the program print?
Func<int, int> f = x => x + 1;
int a = f(5);
f = x => x * 10;
Console.WriteLine($"{a} {f(5)}");6 50
- Expecting
50 50:int a = f(5)runs the lambda once and keeps the number6; a later change offdoes not reacha. - Expecting a delegate variable to keep its first method:
f = x => x * 10;replaces it, and the next call runs the new lambda.
- What would the program print if its last line were
Console.WriteLine(f(a));? - How would you declare a
Functhat takes twointvalues and returns astring?