Home »
C#.Net
Convert char array to string in C#
C# | Convert char[] to string: Here, we are going to learn how to convert char array to string in C#?
Submitted by IncludeHelp, on February 10, 2019
Given a character array and we have to convert it into a string.
char[] to string in C#
In C#, we can convert a character array to the string, for this – we can create a new string from the character array.
Syntax:
string string_object = new string(character_array);
It accepts a character array as an arguments and creates new string.
Example:
Input:
char[] char_arr = { 'H', 'e', 'l', 'l', 'o'};
Creating string:
string str = new string(char_arr);
Output:
str = "Hello"
Code:
using System;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
char[] char_arr = { 'H', 'e', 'l', 'l', 'o'};
//converting char[] to string
string str = new string(char_arr);
//printing string
Console.WriteLine("str = " + str);
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
str = Hello