Nano HE
Nano HE

Reputation: 9307

Need help for C# abstract properties sample code dissection

When reading the tutorial of "Properties 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);
   }

Upvotes: 0

Views: 643

Answers (2)

redjackwong
redjackwong

Reputation: 1568

This is just a demo, the author simplely like this way to demo the code I think, but there's no relationships between them.

Upvotes: 1

Paul Creasey
Paul Creasey

Reputation: 28834

The ToString/writeline methods are not related to overriding Area, it is a demonstration to show the use of an overriden property.

Upvotes: 3

Related Questions