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
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...
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.