This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using static System.Console; | |
class Test | |
{ | |
static void M<T>(string s, T t) | |
{ | |
WriteLine($"Generic : s = {s}, t = {t}"); | |
} | |
static void M(string t, string s) | |
{ | |
WriteLine($"Non Generic: s = {s}, t = {t}"); | |
} | |
static void Main() | |
{ | |
M("Hello", "World"); | |
M("Hello", t: "World"); | |
M(s:"Hello", t: "World"); | |
} | |
} |
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