Why does the string type have a .ToString() method?

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;
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)