Tricky Code
Without running the code, what is the result of this masterpiece?
class Program
{
static void Main(string[] args)
{
DoSomething("a","b");
}
public static void DoSomething<T>(IList<T> set)
{
Console.WriteLine(set.Count);
}
public static void DoSomething<T>(params T[] items)
{
List<T> set = new List<T>();
foreach (T t in items)
{
if (t == null)
continue;
set.Add(t);
}
DoSomething(set);
}
}
It surprised the hell out of me until I figured out what was going on, then I was very amused. This code works exactly as it should be, to produce a very different result than the expected one.