Is it possible to have a virtual/abstract field in a C# class? If so, how is it done?
No. Fields are just there to hold data.
C# Abstract Class Features An abstract class can implement code with non-Abstract methods. An Abstract class can have modifiers for methods, properties etc. An Abstract class can have constants and fields.
Virtual properties behave like virtual methods, except for the differences in declaration and invocation syntax. It is an error to use the virtual modifier on a static property. A virtual inherited property can be overridden in a derived class by including a property declaration that uses the override modifier.
An abstract class may have static fields and static methods. You can use these static members with a class reference (for example, AbstractClass.
A Virtual/Abstract field? No. Fields are just there to hold data. There's nothing to implement.
You can define a Virtual/Abstract Property though.
You can however have virtual or abstract properties:
public abstract string ModelName { get; set; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With