Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
System Namespace
Object Class
Object Methods
 ToString Method
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Object..::.ToString Method

Updated: November 2007

Returns a String that represents the current Object.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Visual Basic (Declaration)
Public Overridable Function ToString As String
Visual Basic (Usage)
Dim instance As Object
Dim returnValue As String

returnValue = instance.ToString()
C#
public virtual string ToString()
Visual C++
public:
virtual String^ ToString()
J#
public String ToString()
JScript
public function ToString() : String

Return Value

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

The following code example demonstrates what ToString returns.

Visual Basic
Public Class Sample
    Public Shared Sub Main()
        ' Displays: "System.Object"
        Dim o As New Object()
        Console.WriteLine(o.ToString())
    End Sub 
End Class 

C#
using System;

public class Sample
{
    public static void Main() {

        // Prints out: "System.Object"
        Object o = new Object();
        Console.WriteLine (o.ToString());

    }
}

Visual C++
#using <System.DLL>

using namespace System;
ref class Sample
{
private:
   void Method()
   {

      // Prints out: "System.Object"
      Object^ o = gcnew Object;
      Console::WriteLine( o->ToString() );
   }

};


J#
import System.*;

public class Sample
{
    void Method()
    {
        // Prints out: "System.Object"
        Object o = new Object();
        Console.WriteLine(o.ToString());
    } //Method 
} //Sample

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker