What will be the output of the following code that is using delegates?
class Program
{
delegate void Operation();
static void Main(string[] args)
{
var operations = new List<Operation>();
for (var i = 0; i < 10; i++)
{
operations.Add(delegate { Console.WriteLine(i); });
}
foreach (var operation in operations)
{
operation();
}
}
}
Experience Level: Not defined
Tags: .NETC#Code challenge
Answer
Related C# job interview questions
Write a code that takes an integer number and outputs its digits to the console.
.NETC#Code challenge Not definedWhat is variable capturing good for and how does it work?
.NETC# Not definedCould you describe what generic type inference is and what will be the output of this program?
.NETC#Code challenge Not definedWhat is the difference between IEnumerable and IQueryable?
.NETC#Entity FrameworkLINQPerformance Not definedWhat is boxing and unboxing?
.NETC#Performance Not defined