dibagaran / cs-2015-7-alpha

C# / July 2015 / Group 1 (Sundays & Tuesdays 15-18)
GNU General Public License v2.0
14 stars 11 forks source link

Session 9 program #4

Closed muhammadbaneshi closed 9 years ago

muhammadbaneshi commented 9 years ago

in line 44 Why not write public virtual string ToString () what is the story?

AMINEDGE commented 9 years ago

Because The ToString() Method has existed in object class(which every datatypes and classes have inherited from that) as a virtual method, so if you want to change or use the method in your class (like Shape class for example) you have to use it as an override method because as I said every Classes in C# inherit from object class, and actually all of them are object, so that's why we call C# Object Oriented.

muhammadbaneshi commented 9 years ago

I do not understand. ToString() method in first time is override. Not exist before.

AMINEDGE commented 9 years ago

It exists in 'object' class which is inaccessible to you but you can use object as a datatype or use it for boxing and unboxing.