Why does the string type have a .ToString() method?
c#, string
Solution
The type `System.String`, like almost all types in .NET, derives from `System.Object`. `Object` has a `ToString()` method and so `String` inherits this method. It is a virtual method and `String` overrides it to return a reference to itself rather than using the default implementation which is to return the name of the type.
From Reflector, this is the implementation of ToString in `Object`:
public virtual string ToString()
{
return this.GetType().ToString();
}
And this is the override in `String`:
public override string ToString()
{
return this;
}
Problem
Why does the string data type have a `.ToString()` method?