Skip to main content

Closures checkpoint

Challenge on lesson: Checkpoint: delegates and closures

CHALLENGE
Difficulty: advanced+25 XP

Implement static List<Func<int>> Counters(int n) returning n functions; function i returns i-th value 0,1,...,n-1 โ€” each counter must return ITS OWN index (proving you captured per-iteration values correctly, not one shared variable). Then implement static Func<int,int> Adder(int start) returning a function that adds its argument to start and returns the RUNNING total (state must persist across calls โ€” a captured mutable local).

Back to lesson: Checkpoint: delegates and closures