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

Comments

No Comments Yet.
Be the first to tell us what you think.