Do you grok C# 2.0?
I run into a couple of great questions in .Net 2.0 today, which influenced some of the things that I did there. I'm wonderring how many others would spot them. Without compiling the code, what is the result of the following code snippet?
using System;
using System.Collections.Generic;
public class Sample<T> where T:class
{
private static string typeName = typeof(T).FullName;
public string TypeName
{
get { return typeName; }
}
public List<Printer> PrintNumbers()
{
string [] names = { "Ayende", "Rahien", "Foo", "Bar" };
List<Printer> list = new List<Printer> ();
foreach(string s in names)
{
list.Add( delegate(){ Console.WriteLine(s); } );
}
return list;
}
}
public delegate void Printer();
public class Start
{
public static void Main()
{
Console.WriteLine(new Sample<Type>().TypeName);
Console.WriteLine(new Sample<string>().TypeName);
foreach(Printer print in new Sample<Start>().PrintNumbers())
{
print();
}
}
}
Hint: In my project, I took advantage of the first and had to work around the second.
Th answers will be posted tomorrow.
Comments
Comment preview