Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is not possible in any .NET language because of type-safety concerns. In type-safe languages, you must provide covariance for return values, and contravariance for parameters. Take this code:</p> <pre><code>class B { S Get(); Set(S); } class D : B { T Get(); Set(T); } </code></pre> <p>For the <code>Get</code> methods, covariance means that <code>T</code> must either be <code>S</code> or a type derived from <code>S</code>. Otherwise, if you had a reference to an object of type <code>D</code> stored in a variable typed <code>B</code>, when you called <code>B.Get()</code> you wouldn't get an object representable as an <code>S</code> back -- breaking the type system.</p> <p>For the <code>Set</code> methods, contravariance means that <code>T</code> must either be <code>S</code> or a type that <code>S</code> derives from. Otherwise, if you had a reference to an object of type <code>D</code> stored in a variable typed <code>B</code>, when you called <code>B.Set(X)</code>, where <code>X</code> was of type <code>S</code> but not of type <code>T</code>, <code>D::Set(T)</code> would get an object of a type it did not expect.</p> <p>In C#, there was a conscious decision to disallow changing the type when overloading properties, even when they have only one of the getter/setter pair, because it would otherwise have very inconsistent behavior (<em>"You mean, I can change the type on the one with a getter, but not one with both a getter and setter? Why not?!?"</em> -- Anonymous Alternate Universe Newbie).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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