Share via


Convert.ToString Method (Char)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Converts the value of the specified Unicode character to its equivalent String representation.

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

Syntax

'Declaration
Public Shared Function ToString ( _
    value As Char _
) As String
public static string ToString(
    char value
)

Parameters

Return Value

Type: System.String
The String equivalent of the value of value.

Remarks

This implementation is identical to Char.ToString.

Examples

The following code sample illustrates the conversion of a Char to a String, using ToString.

Public Sub ConvertStringChar(ByVal stringVal As String)
   Dim charVal As Char = "a"c

   ' A string must be one character long to convert to char.
   Try
      charVal = System.Convert.ToChar(stringVal)
      outputBlock.Text &= String.Format("{0} as a char is {1}", _
                                stringVal, charVal) & vbCrLf
   Catch exception As System.FormatException
      outputBlock.Text &= String.Format( _
       "The string is longer than one character.") & vbCrLf
   Catch exception As System.ArgumentNullException
      outputBlock.Text &= "The string is null." & vbCrLf
   End Try

   ' A char to string conversion will always succeed.
   stringVal = System.Convert.ToString(charVal)
   outputBlock.Text &= String.Format("The character as a string is {0}", _
                             stringVal) & vbCrLf
End Sub
public void ConvertStringChar(string stringVal)
{
   char charVal = 'a';

   // A string must be one character long to convert to char.
   try
   {
      charVal = System.Convert.ToChar(stringVal);
      outputBlock.Text += String.Format("{0} as a char is {1}",
         stringVal, charVal) + "\n";
   }
   catch (System.FormatException)
   {
      outputBlock.Text += String.Format(
         "The string is longer than one character.") + "\n";
   }
   catch (System.ArgumentNullException)
   {
      outputBlock.Text += "The string is null." + "\n";
   }

   // A char to string conversion will always succeed.
   stringVal = System.Convert.ToString(charVal);
   outputBlock.Text += String.Format("The character as a string is {0}",
         stringVal) + "\n";
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

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