My base class declares:
public double Value;
My derived class declares:
public new decimal Value;
In the tip to use the new
keyword, it says: "...Use the new keyword if hiding was intended.
".
This explanation doesn't seem correct. When using the new
keyword, it is not hiding the base variable. It keeps both variables with the same name, and even with different values.
I understand there is a design issue on my side, but I'd like to know why the new
keyword doesn't really hide the base class variable. Also, why the new
keyword is even available if it would mean a design issue (changing data type in the derived class). Is using dynamic
an option here?
The issue is: for most part, double
is fine. However in a few derived classes, it must be decimal
.
This question is focused on the use of the new
keyword for variables in derived classes, not really a discussion of differences between double and decimal.
Thank you.