compiler warning on (ambiguous) method resolution with named parameters
Posted
by FireSnake
on Stack Overflow
See other posts from Stack Overflow
or by FireSnake
Published on 2010-04-17T09:34:11Z
Indexed on
2010/04/17
9:43 UTC
Read the original article
Hit count: 275
c#4.0
|named-parameters
One question regarding whether the following code should yield a compiler warning or not (it doesn't). It declares two methods of the same name/return type, one has an additional named/optional parameter with default value.
NOTE: technically the resolution isn't ambiguous, because the rules clearly state that the first method will get called. See here, Overload resolution, third bullet point. This behavior is also intuitive to me, no question.
public void Foo(int arg) { ... }
public void Foo(int arg, bool bar = true) { ...}
Foo(42); // shouldn't this give a compiler warning?
I think a compiler warning would be kind of intuitive here. Though the code technically is clean (whether it is a sound design is a different question:)).
© Stack Overflow or respective owner