Export (0) Print
Expand All
1 out of 19 rated this helpful - Rate this topic

Object.ToString Method

Returns a String that represents the current Object.

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

public virtual string ToString ()
public String ToString ()
public function ToString () : String
Not applicable.

Return Value

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.

using System;

public class Sample
{
    void Method() {

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

    }
}

import System.*;

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

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.