Export (0) Print
Expand All

Convert.ToString Method (String)

Returns the specified string instance; no actual conversion is performed.

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

public static string ToString(
	string value
)

Parameters

value
Type: System.String

The string to return.

Return Value

Type: System.String
value is returned unchanged.

The following example passes a string to the ToString(String) method and calls the Object.ReferenceEquals method to confirm that the method returns the original string. The example also calls the String.IsInterned method to ensure that the two strings are not identical because the original string is interned.

using System;

public class Example
{
   public static void Main()
   {
      String article = "An";
      String noun = "apple";
      String str1 = String.Format("{0} {1}", article, noun);
      String str2 = Convert.ToString(str1);

      Console.WriteLine("str1 is interned: {0}",
                        ! (String.IsInterned(str1) == null));
      Console.WriteLine("str1 and str2 are the same reference: {0}",
                        Object.ReferenceEquals(str1, str2));
   }
}
// The example displays the following output: 
//       str1 is interned: False 
//       str1 and str2 are the same reference: True

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft