Given a character, the task is to character to the string in C#.
Examples:
Input : X = 'a' Output : string S = "a" Input : X = 'A' Output : string S = "A"
Approach: The idea is to use ToString() method, the argument is the character and it returns string converting Unicode character to the string.
// convert the character x // to string s public string ToString(IFormatProvider provider);
C#
// C# program to character to the string using System; public class GFG{ static string getString(char x) { // Char.ToString() is a System.Char // struct method which is used // to convert the value of this // instance to its equivalent // string representation string str = x.ToString(); return str; } static void Main(string[] args) { char chr = 'A'; Console.WriteLine("Type of "+ chr +" : " + chr.GetType()); string str = getString(chr); Console.WriteLine("Type of "+ str +" : " + str.GetType()); } } |
chevron_right
filter_none
Output:
Type of A : System.Char Type of A : System.String
Recommended Posts:
- Convert String to Character Array in C#
- C# | Convert.ToSingle(String, IFormatProvider) Method
- C# | Convert.ToString(String, IFormatProvider) Method
- C# | Convert.FromBase64String(String) Method
- C# | Convert.ToBoolean(String, IFormatProvider) Method
- C# | Convert.ToByte(String, IFormatProvider) Method
- C# | Convert.ToDateTime(String, IFormatProvider) Method
- C# | Convert.ToChar(String, IFormatProvider) Method
- C# | Convert.ToDecimal(String, IFormatProvider) Method
- C# | Convert.ToInt32(String, IFormatProvider) Method
- C# | Convert.ToDouble(String, IFormatProvider) Method
- C# | Convert.ToInt16(String, IFormatProvider) Method
- C# | Convert.ToSByte(String, IFormatProvider) Method
- C# | Convert.ToInt64(String, IFormatProvider) Method
- C# | Convert.ToUInt16(String, IFormatProvider) Method
- C# | Convert.ToUInt32(String, IFormatProvider) Method
- C# | Convert.ToUInt64(String, IFormatProvider) Method
- Different ways to convert String to Integer in C#
- Different Ways to Convert Char Array to String in C#
- C# Program to Convert the Octal String to an Integer Number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

