Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Because there is already an implicit conversion from <code>Derived</code> to <code>BaseClass</code>, and the converse does not make any sense.</p> <p>Regarding the latter: if your <code>Base</code> objects are meant to be implicitly convertible to <code>Derived</code> -- why aren't they <code>Derived</code> objects in the first place?</p> <p>Obligatory quotes from the <a href="http://www.ecma-international.org/publications/standards/Ecma-334.htm">standard</a>:</p> <blockquote> <h2>6.1.6 Implicit reference conversions</h2> <p>The implicit reference conversions are:</p> <ul> <li>[...]</li> <li>From any class-type S to any class-type T, provided S is derived from T.</li> </ul> </blockquote> <p>This says there's an implicit conversion <code>Derived</code> => <code>Base</code>, as we all know.</p> <blockquote> <h2>6.2.4 Explicit reference conversions</h2> <p>The explicit reference conversions are:</p> <ul> <li>[...]</li> <li>From any class-type S to any class-type T, provided S is a base class of T.</li> <li>[...]</li> </ul> </blockquote> <p>This says there's already an explicit conversion <code>Base</code> => <code>Derived</code> (which is what allows you to try downcasting at runtime).</p> <blockquote> <h2>6.4.1 Permitted user-defined conversions</h2> <p>C# permits only certain user-defined conversions to be declared. <strong>In particular, it is not possible to redefine an already existing implicit or explicit conversion.</strong></p> </blockquote> <p>And this says that since the two conversions of interest are already defined by the language, you can't redefine them.</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