.NET Framework Class Library for Silverlight
Object..::.ToString Method

Returns a String that represents the current Object.

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

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

Return Value

Type: System..::.String
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.

Examples

The following code example demonstrates what ToString returns.

Visual Basic
Public Class Example
   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      ' Displays: "System.Object"
      Dim o As New Object()
      outputBlock.Text &= o.ToString() & vbCrLf
   End Sub
End Class
C#
using System;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {

      // Prints out: "System.Object"
      Object o = new Object();
      outputBlock.Text += o.ToString() + "\n";

   }
}
Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference

Tags :


Page view tracker