This documentation is archived and is not being maintained.
String::ToString Method
Visual Studio 2010
Returns this instance of String; no actual conversion is performed.
Assembly: mscorlib (in mscorlib.dll)
The following example demonstrates the ToString method. Note that the ToString() method is not called explicitly; instead, it is called implicitly because the Console::WriteLine(String, Object) method uses the composite formatting feature.
using namespace System; int main() { String^ str1 = "123"; String^ str2 = "abc"; Console::WriteLine( "Original str1: {0}", str1 ); Console::WriteLine( "Original str2: {0}", str2 ); Console::WriteLine( "str1 same as str2?: {0}", Object::ReferenceEquals( str1, str2 ) ); str2 = str1; Console::WriteLine(); Console::WriteLine( "New str2: {0}", str2 ); Console::WriteLine( "str1 same as str2?: {0}", Object::ReferenceEquals( str1, str2 ) ); } /* This code produces the following output: Original str1: 123 Original str2: abc str1 same as str2?: False New str2: 123 str1 same as str2?: True */
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: