the code below causes the following compilation error:
Why?
internal class Animal {
protected virtual string prop; //<- error here: the modifier virtual is not valid for this item
}
On windows docs it implies protected is an allowed keyword (and i see no reason it wouldn't be).
The same question was asked here, but the answer said "the access specifier must match the parent class". In the above example there is no parent class.
I'm using C# 10 on .NET6
In your current code
propis not a property, but a field.And fields cannot be
virtual:(emphasis is mine)
To make it a property, you must supply
getandsetmethods,or specify to use their default version, like this: