Convert Char Array to String in C#

You can convert a char array to a string in C# using the following:

  1. String constructor
  2. String.Join method
  3. String.Concat() method
  4. char.ToString() method

Using string constructor:

char[] chArray = { 'h', 'e', 'l', 'l', 'o' }; string str = new string(chArray); Console.WriteLine(str); //Output: hello

Using String.Join() method:

char[] chArray = { 'h', 'e', 'l', 'l', 'o' }; string str = string.Join("", chArray); Console.WriteLine(str); //Output: hello

Using String.Concat() method:

You can use the String.Concat method in C# to convert a char array to a string. The String.Concat method concatenates all the elements of a specified array or an IEnumerable of strings into a single string.

char[] chArray = { 'h', 'e', 'l', 'l', 'o' }; string str = String.Concat(chArray); Console.WriteLine(str); //Output: hello

Using char.ToString():

You can use the char.ToString method to convert a char array to a string in C#. The char.ToString method returns a string that represents a specified Unicode character. You can loop through the elements of the char array and call the char.ToString method on each element to get a string representation of each character, then concatenate the strings to form the final string.

char[] chArray = { 'h', 'e', 'l', 'l', 'o' }; string str = ""; foreach (char c in chArray) { str += char.ToString(c); } Console.WriteLine(str); //Output: hello

C# char array

A char array in C# is an array of characters. It is used to store a sequence of characters as a single unit. The char data type in C# is a Unicode character, which is a data type that can store any character in the Unicode standard.

Here's an example of declaring and initializing a char array in C#:

char[] chArray = {'a', 'b', 'c', 'd', 'e'};

C# String.Join()

string.Join is a method in C# that concatenates a specified separator string between elements of a string array or an object array, producing a single concatenated string. Syntax:
string.Join(separator, values);

Where separator is the string used to separate the elements in the concatenated string, and values is the array of strings to concatenate.

C# String.Concat()

String.Concat is a method in C# that concatenates two or more strings into a single string.

Syntax:
String.Concat(str1, str2, ...);

Where str1, str2, ... are the strings to concatenate.