Mohanapriya R Mohanapriya R
Updated date Aug 16, 2024
In this article, we will explore converting char to strings in C#. Learn the techniques, including the use of the ToString() method and string concatenation,
  • 1.7k
  • 0
  • 0

Character to String Conversion in C#

In C#, a character can be easily converted to a string using the ToString() method or by concatenating it with an empty string. The ToString() method applies to any data type, including characters, and returns the character's string representation.

using System;

class Program
{
    static void Main()
    {
        // Converting character to string using ToString() method
        char myChar = 'A';
        string charToString1 = myChar.ToString();

        // Converting character to string by concatenating with an empty string
        string charToString2 = myChar + "";

        // Displaying the results
        Console.WriteLine("Converted using ToString(): " + charToString1);
        Console.WriteLine("Converted by concatenation: " + charToString2);
    }
}

In the above sample program, the character 'A' is converted to a string using both the ToString() method and concatenation with an empty string. The ToString() method is used to convert the character directly to its string. 

Output:

Converted using ToString(): A
Converted by concatenation: A

Comments (0)

There are no comments. Be the first to comment!!!