System Namespace Object Class
Returns a String that represents the current Object.
[ VB ]
Overridable Public Function ToString ( ) As String
[ C# ]
public virtual string ToString ( );
[ C++ ]
public: virtual String* ToString ( );
[ JScript ]
public function ToString ( ) : String;
A String that represents the current Object.
This method returns a human-readable string that is culture-sensitive. 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.
The default implementation returns the fully qualified name of the type of the Object.
Notes to Implementers: This method can be overridden in a derived class to return values that are meaningful for that type. For example, the base data types, such as Int32, implement ToString so that it returns the string form of the value that the object represents. Derived classes that require more control over the formatting of strings than ToString provides should implement IFormattable, whose ToString method uses the current thread's CurrentCulture property.
The following code example demonstrates what ToString returns.
[ VB ]
Imports System
Public Class Sample
Sub Method ( )
' prints out: "System.Object"
Dim o As New Object ( )
Response.Write ( o.ToString ( ) )
End Sub 'Method
End Class 'Sample
[ C# ]
using System;
public class Sample
{
void Method ( ) {
// prints out: "System.Object"
Object o = new Object ( );
Response.Write ( o.ToString ( ) );
}
}
[ C++ ]
#using <mscorlib.dll>
#using <System.DLL>
using namespace System;
__gc class Sample
{
void Method ( )
{
// prints out: "System.Object"
Object *o = new Object ( );
Console::WriteLine ( o->ToString ( ) );
}
};
Object Members String