Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>UPDATE: <a href="http://blogs.msdn.com/b/ericlippert/archive/2011/05/12/optional-argument-corner-cases-part-two.aspx" rel="noreferrer">This question was the subject of my blog on May 12th 2011. Thanks for the great question!</a></p> <p>Suppose you have an interface as you describe, and a hundred classes that implement it. Then you decide to make one of the parameters of one of the interface's methods optional. Are you suggesting that the right thing to do is for the compiler to force the developer to find every implementation of that interface method, and make the parameter optional as well?</p> <p>Suppose we did that. Now suppose the developer did not have the source code for the implementation:</p> <hr> <pre><code>// in metadata: public class B { public void TestMethod(bool b) {} } </code></pre> <hr> <pre><code>// in source code interface MyInterface { void TestMethod(bool b = false); } class D : B, MyInterface {} // Legal because D's base class has a public method // that implements the interface method </code></pre> <p>How is the author of D supposed to make this work? Are they required in your world to call up the author of B on the phone and ask them to please ship them a new version of B that makes the method have an optional parameter? </p> <p>That's not going to fly. What if <em>two</em> people call up the author of B, and one of them wants the default to be true and one of them wants it to be false? What if the author of B simply refuses to play along?</p> <p>Perhaps in that case they would be required to say:</p> <pre><code>class D : B, MyInterface { public new void TestMethod(bool b = false) { base.TestMethod(b); } } </code></pre> <p>The proposed feature seems to add a lot of inconvenience for the programmer with no corresponding increase in representative power. What's the compelling benefit of this feature which justifies the increased cost to the user?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload