Mono Class Library: System.Object Overview | MembersSystem.Object.ToString Method |
Creates and returns a string representation of the current instance. [Edit]
|
A string representation of the current instance. [Edit]
Operation
object.ToString returns a string whose content is intended to be understood by humans. Where the object contains culture-sensitive data, the string representation returned by object.ToString takes into account the current system culture. For example, for an instance of the double class whose value is zero, the implementation of double.ToString might return "0.00" or "0,00" depending on the current UI culture.Note: Although there are no exact requirements for the format of the returned string, it should as much as possible reflect the value of the object as perceived by the user.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.
Note: The value returned includes the full name of the type.Note to Inheritors
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.
[Edit]
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
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0