Creates and returns a string representation of the current instance.
A string representation of the current instance.
object.ToString is equivalent to calling object.GetType to obtain the Type object for the current instance and then returning the result of calling the object.ToString implementation for that type.
It is recommended, but not required, that object.ToString be overridden in a derived class to return values that are meaningful for that type. For example, the base data types, such as int, implement object.ToString so that it returns the string form of the value the object represents.
Subclasses that require more control over the formatting of strings than object.ToString provides should implement IFormattable, whose object.ToString method uses the culture of the current thread.
The following example outputs the textual description of the value of an object of type object to the console.
C# Example
using System;
class MyClass {
static void Main() {
object o = new object();
Console.WriteLine (o.ToString());
}
}
The output is
System.Object