Monday, December 29, 2008

C# Brainteasers

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

using System;
using System.Collections.Generic;
class Test{

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

1 comment:

Unknown said...

Sorry but that code won't compile. You are using List in a non-generic way.

Computers Add to Technorati Favorites Programming Blogs - BlogCatalog Blog Directory