1
Reply

Print, print, print...

Akkiraju Ivaturi

Akkiraju Ivaturi

Sep 7 2012 11:22 PM
929

Here's some code using the anonymous method feature of C# 2. What does it do?


using System;
using System.Collections.Generic;

class Test
{
delegate void Printer();

static void Main()
{
List<Printer> printers = new List<Printer>();
for (int i=0; i < 10; i++)
{
printers.Add(delegate { Console.WriteLine(i); });
}

foreach (Printer printer in printers)
{
printer();
}
}

}  


Answers (1)