As Jared points out, this is not possible. However, it is interesting to consider why not.
Assume the field is private. Then it may not be available in the derived class B. (Assuming B is not a nested type of A.)
Assume the field is not private. It does not matter if it is publicly available, internal, protected or protected internal. Suppose his audience and that were legal. Now you have the following situation.
class B : A { override public D argument;
And hey, you just crashed while you work. You just wrote an object of type E in a field that can only store type D. (We could do similar failure scenarios for other configurations, such as protected fields, etc.)
Now you can say, well, instead, let me make the property read-only. What I can virtualize:
class A { public virtual C Argument { get; } } class B : A { public override D Argument { ... } }
Now the problems are gone. The open interface is not writable, so there is no problem that someone writes something there that is not supported. And the property is virtual, so there is a mechanism for overriding it.
This function is called "return type covariance," and it is not supported in C #. See Why are the concepts of "Covariance" and "Contravariance" applicable to the implementation of interface methods? .
Please explain what you are really trying to do, not how you are trying to do it. There is probably a better way.
source share