Is it possible to have a virtual/abstract field in a C# class? If so, how is it done?
相关问题
- how to define constructor for Python's new Nam
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
You can however have virtual or abstract properties:
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.
Properties can be virtual, may be you can gain on that. At least it is heavily used in NHibernate.
Basically you have to have a method to virtualize, how should the virtual field work?
No. fields can not be virtual\abstract but properties can.
The first sentence of the MSDN documentation answers your question:
http://msdn.microsoft.com/en-us/library/9fkccyh4(v=vs.80).aspx
No. You'd have to use a property to accomplish what you seem to what to do.