Aug 25, 2017

Surprises in C#

Ok, after a long period of silence I decided to take some time to write about one detail of C# that stroke me yesterday. Given the following C# snipped, what you expect as the output ? (ok, I hand picked this example which I see as an extreme corner case)



To my surprise the middle one invokes the generic version of M (now that I've thought more about it, it makes sense).

The outcome of this little experiment is that I feel even more compelled to stay away from introducing generic/non generic versions of a method.

Happy codding

No comments: