开发者

Need help for C# abstract properties sample code dissection

开发者 https://www.devze.com 2022-12-15 12:07 出处:网络
When reading the tutorial of \"Propert开发者_开发百科ies Tutorial\" from MSDN. I\'m consused about the example.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号