How to convert a character to a string in C#

Overview

We can convert a character to a string in C# using the ToString() method. It converts a character value to its equivalent string representation.

Syntax

public static string ToString (char c);

Parameters

c: The character we want to change to string.

Return Value

The value returned is a string representation of the specified character.

Example

We will convert some characters to strings in the code below using the ToString() method:

// use System
using System;
// create class
class HelloWorld
{
// main method
static void Main()
{
// create characters
char c1 = 'Y';
char c2 = 'E';
char c3 = 'S';
// conver to strings
string s1 = Char.ToString(c1);
string s2 = Char.ToString(c2);
string s3 = Char.ToString(c3);
// print returned value
Console.WriteLine(s1);
Console.WriteLine(s2);
Console.WriteLine(s3);
}
}

Explanation

From the code above, we convert the characters to strings using the ToString() method.

  • In line 10 to line 12 we create some character variables and create initials for them.
  • In line 15 to line 17 we convert the characters to strings using the ToString() method.
  • From line 20 to line 22 we print the results.