I'd expect this behaviour because the compiler knows the default values of optionalstr
and optionalint
and is therefore able to make a decision based on that on what values to use. It wouldn't know what to set as the value for int[] optionalint
. Since the compiler is "more sure" of what to use when you have the optional parameters, it calls that method.
If you added an extra method like this
public static string ExampleMethod(int required)
{
return "ExampleMethod 3";
}
this would be the method called because the compiler will go for the method that has no optional parameters first.
More detailed explanation on overload resolution.