Updated: March 2011
Returns a string that represents the current object.
Assembly: mscorlib (in mscorlib.dll)
is the major formatting method in the .NET Framework. It converts an object to its string representation so that it is suitable for display. (For information about formatting support in the .NET Framework, see Formatting Overview.)
The default implementation of the method returns the fully qualified name of the type of the Object, as the following example shows.
Because Object is the base class of all reference types in the .NET Framework, this behavior is inherited by reference types that do not override the method. The following example illustrates this. It defines a class named Object1 that accepts the default implementation of all Object members. Its method returns the object's fully qualified type name.
Types commonly override the method to return a string that represents the object instance. For example, the base types such as Char, Int32, and String provide implementations that return the string form of the value that the object represents. The following example defines a class, Object2, that overrides the method to return the type name along with its value.
When you implement your own types, you should override the method to return values that are meaningful for those types. Derived classes that require more control over formatting than provides can implement the IFormattable interface. Its IFormattable.ToString(String, IFormatProvider) method enables you to define format strings that control formatting and to use an IFormatProvider object that can provide for culture-specific formatting.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, 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, Zune
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.