Today I discovered something strange. I wonder why this works:
static void Main(string[] args)
{
Console.WriteLine(ExampleMethod(3));
Console.ReadKey();
}
public static string ExampleMethod(int required, params int[] optionalint)
{
return "ExampleMethod 2";
}
public static string ExampleMethod(int required, string optionalstr = "default string", int optionalint = 10)
{
return "ExampleMethod 1";
}
Think about it: What is the result when you call ExampleMethod(3);
In my opinion it leads to an unpredictable result. In my case always Method 1 was called. But as I changed the signature of Method 1, the Main Method called Method 2 (of course).
I did not expect such a behavior, I expected an "AmbiguousReferenceException" or at least a compiler warning.