Can you use virtual, override, or abstract keywords on an accessor of a static property?
Short answer
No, static members in C# belong to the type itself rather than to any specific instance, so they cannot participate in polymorphism, which means you cannot use the virtual, override, or abstract keywords on a static property or its accessors.
Advertisement
AModel answer
No, static members in C# belong to the type itself rather than to any specific instance, so they cannot participate in polymorphism, which means you cannot use the virtual, override, or abstract keywords on a static property or its accessors. Polymorphic behavior through these keywords only applies to instance members, since overriding fundamentally relies on the actual runtime type of an object instance, which static members simply do not have.
public class Base {
// This is not allowed and will cause a compiler error
// public static virtual int Value { get; set; }
}Real-world example
A developer attempting to make a shared configuration value overridable across subclasses using a static virtual property quickly discovers this is not allowed in C#, and instead redesigns the solution using an instance based virtual property.
Likely follow-ups
- How can you achieve similar shared, overridable behavior without using static members?
- Why does polymorphism require instance level members specifically?
Related topics