From what I can tell, properties are used to provide accessor method-esque functionality; however, they do so at the cost of normal method inheritance behavior. Are there any advantages to using properties versus conventional setter/getter methods? What are the pros/cons of properties and accessor methods?
From what I can tell, properties are used to provide accessor method-esque functionality; however,
Share
I think you might be confused. In your examples, the above methods should be accessible. For example, given this set of types, the following should work:
The derived class still inherits the property. Properties really are just syntactic sugar in C# (mostly), as the compiler is generating
set_Datum(int x)andget_Datum()methods behind the scenes for you. The property get/set methods can still be overridden individually as shown above.The advantage of using properties is that they have additional semantic meaning; they “contain” or “represent” data in some fashion, not a method for generating the data.