I override it to also create the output I want from a class when I archive it.
I will then use the .ToString().GetHashCode() to override the GetHashCode() method
I will also override the .Equals() with ToString().Equals(((MyObj)obj).ToString());
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
Hi dude.,
Do you know System.Object is the root class of .net framework from this only all the class are derived. In System.Object ToString() method defined as abstract method because fields in object is not stable format so we must need to override ToString() method to covert object into string
mani-hellboy
Junior Poster in Training
69 posts since Feb 2012
Reputation Points: 0
Solved Threads: 7
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
mani-hellboy
Junior Poster in Training
69 posts since Feb 2012
Reputation Points: 0
Solved Threads: 7
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
One important use of overriding the ToString method in your classes is for consistency in the display of information in your views. It is far easier to override the ToString method than to remember the format used in each view for your class.
Say for example that I have a class called Employee. Let's say I want my employee record to always be displayed as first name followed by a space followed by the surname. Overriding the ToString method allows it to be performed in one place, while you may have several views containing employee information, say an employee list, a sales figures list and a graphical representation of their sales figures. To be consistent I would have to apply this formatting in three places rather than the one.
darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200