Need help for C# abstract properties sample code dissection
When reading the tutorial of "Propert开发者_开发百科ies Tutorial" from MSDN. I'm consused about the example.
How to define abstract properties. ...
When I debug, I found each of the three override double Area() is invoked by ToString(); and ToString() is invoked default by the WriteLine() calls.
What's the benefit calling this way? I feel it is not a short way to override double Area().
public override string ToString()
{
return Id + " Area = " + string.Format("{0:F2}",Area);
}
The ToString/writeline methods are not related to overriding Area, it is a demonstration to show the use of an overriden property.
This is just a demo, the author simplely like this way to demo the code I think, but there's no relationships between them.
精彩评论