Hi,
I have seen in couple of places the code where ToString() method has been overriden. Like :
class Employee : IComparable<Employee>
{
public int Salary { get; set; }
public string Name { get; set; }
public int CompareTo(Employee other)
{
if (this.Salary == other.Salary)
{
return this.Name.CompareTo(other.Name);
}
return other.Salary.CompareTo(this.Salary);
}
public override string ToString()
{
// String representation.
return this.Salary.ToString() + "," + this.Name;
}
}
What is the need of overriding. I have seen if we dont override we do not get the value instead we get the object only. Why so ?
Plz reply if you have any idea.
Thanks.
Regards