The C# Language Specification says:
A virtual property declaration specifies that the accessors of the property
are virtual. The virtual modifier applies to both accessors of a read-write
property - it is not possible for only one accessor of a read-write property
to be virtual.
An abstract property declaration specifies that the accessors of the
property are virtual, but does not provide an actual implementation of the
accessors. Instead, non-abstract derived classes are required to provide
their own implementation for the accessors by overriding the property.
Because an accessor for an abstract property declaration provides no actual
implementation, its accessor-body simply consists of a semicolon.
Does this mean it is possible for only one accessor of a read-write property
to be abstract (both get and set are virtual)?
I tried:
interface A
{
int X { get; set; }
}
abstract class B : A
{
virtual public int X
{
get
{
return 0;
}
}
}
class C : B
{
override public int X
{
// use base class getter
set
{
throw new Exception("Illegally tried to set X.");
}
}
}
But no matter omit the setter in abstract class B, leave it empty, try to
use the abstract keyword, I always get an error. I know I can use an
abstract member function for this, but how can I leave the setter undefined
(since B is abstract after all)?