|
-
Jan 6th, 2010, 11:54 PM
#1
Thread Starter
Hyperactive Member
why we need to override tostring method
hi,
i have found a class with two properties, name and id...
id is set and get directly using property ....
but name is only set using property and returning name using overriding the tostring method in the class....
i have seen many times, that the tostring() method is overrided in a class... can anyone brief why that done ?
thankzzzzzzz
-
Jan 7th, 2010, 02:02 AM
#2
Re: why we need to override tostring method
You override it so that when the method is called with an instance of your class then you can control what is returned by the ToString method. You can combine different fields like first name and lastname,etc...
-
Jan 7th, 2010, 06:36 AM
#3
Re: why we need to override tostring method
Overriding the ToString method can be invaluable for custom classes. For example, an Employee class could override its ToString method to return a formatted string containing the first and last name.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|