Convert Char to String in C#

In C#, a char is a single Unicode character and a string is a sequence of Unicode characters. Converting a char to a string is a common operation in C# programming.

Syntax:
public static string ToString (char ch);
Return:

It will returned a string representation of the specified character

Here are the ways to convert a char to a string in C#:

Using ToString() Method:

char c = 'a'; string s = c.ToString(); Console.WriteLine(s); //Output: a

The ToString() method returns a string representation of the current char.

Using string Constructor:

char c = 'a'; string s = new string(c, 1); Console.WriteLine(s); //Output: a

The string constructor takes two arguments, the first argument is the char to be converted and the second argument is the number of times the char should appear in the resulting string. In this example, the char c is converted to a string with a length of 1.

Using String Interpolation:

char c = 'a'; string s = $"{c}"; Console.WriteLine(s); //Output: a

String Interpolation allows you to embed expressions inside string literals. The expression {c} is evaluated and the result is concatenated with the string literal to produce the final string.

These are the ways to convert a char to a string in C#. Depending on the situation, you can choose the most appropriate method to convert a char to a string.

C# ToString()

The ToString() method in C# is a virtual method defined in the System.Object class, which is the base class of all objects in C#. The ToString() function provides a string version of the object it's invoked on.

C# String Interpolation

String Interpolation in C# is a feature that allows you to embed expressions inside string literals, which are then evaluated and concatenated with the string literal to produce the final string. The expression is surrounded by curly brackets {}. String Interpolation is a convenient way to build strings dynamically, as it eliminates the need for string concatenation or string formatting. It's also easier to read, as the expressions are clearly visible in the string literal.