|
new is used to change the behavior of a method or a property implemented in its base class.
Specifically in the program fragment of the landlord:
public new string AddElementName
AddElementName, is a property of the current derived class that returns a string type
This property is inherited, if you do not want this property as defined in the base class
Realize that way, you can override this property: public string AddElementName
Note that the above is not added new, so there is no problem to write, but the compiler will issue
Warning (it worried that you accidentally overwritten the AddElementName property of the base class), in order
Don't let the compiler issue a warning (also shows that you really want to override this attribute), you can
Add new, like this: public new string AddElementName
In this way, the compiler knows that you are very clear that you are overwriting the attribute and you will not be alerted.
In the code snippet of the landlord:
public new string AddElementName
{
get
{
return base.AddElementName;
}
set
{
base.AddElementName = value;
}
}
The derived class explicitly overrides the AddElementName property of the base class, but from its implementation point of view,
But it is realized by directly calling the AddElementName attribute of the base class. It feels like there is no disease and moaning.
A more appropriate analogy is: take off the quilt and fart --> do more
The above, on behalf of my personal point of view, I do not know if it is right, and then listen to the lecture downstairs. |
|