Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
6 out of 9 rated this helpful - Rate this topic

Object.ToString Method

Returns a String that represents the current Object.

[Visual Basic]
Public Overridable Function ToString() As String
[C#]
public virtual string ToString();
[C++]
public: virtual String* ToString();
[JScript]
public function ToString() : String;

Return Value

A String that represents the current Object.

Remarks

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 must implement IFormattable, whose ToString method uses the current thread's CurrentCulture property.

Example

[Visual Basic, C#, C++] The following code example demonstrates what ToString returns.

[Visual Basic] 
Imports System

Public Class Sample
    
    Sub Method()

        ' Prints out: "System.Object"
        Dim o As New Object()
        Console.WriteLine(o.ToString())

    End Sub 'Method
End Class 'Sample

[C#] 
using System;

public class Sample
{
    void Method() {

        // Prints out: "System.Object"
        Object o = new Object();
        Console.WriteLine (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());

   }
};

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Object Class | Object Members | System Namespace | String

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.