Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumC#delegates Func ActionSingle-choice MCQ

What is the output of this loop using a captured variable in a deferred query, given C# 5+ foreach semantics?

var actions = new List<Func<int>>(); for (int i = 0; i < 3; i++) { int copy = i; actions.Add(() => copy); } foreach (var a in actions) Console.Write(a());