String.ToString Method
.NET Framework 4.5
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 example does not explicitly call the ToString method. Instead, the method is called implicitly by the composite formatting feature.
using System; class stringToString { public static void 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.ToString(); 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 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.