asp.net.ph

Object.ToString Method

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;

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

Example

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 ( ) );

   }
};
See Also

Object Members   String Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph