Overload Resolution Revisited in .Net 4.5

Overload resolution has always been an area of frequent attention for the compiler team. So, once again some major changes have been incorporated to make the compiler more intelligent. Let's have a look at the given below snippet (picked from MSDN) first, and then let's try to predict the output:


 
Output in Visual Studio 2010: ExampleMethod: p2 is object
Output in Visual Studio 2012/13: ExampleMethod: p2 is string

Explanation of code: In the above code, there are two overloads with a difference of 3rd parameter params and bit a different ordering of parameters.

Visual Studio 2010 picks the overload without the params parameter, whereas, the Visual Studio 2012 compiler is smarter and it picks the overload which has a more specific type.

If all your overloads precisely do the same thing, then this change will not be a problem. But in other cases, it may lead to crashes or exceptions.

So, going forward, be careful while offering method overloads.