How to convert an array of characters into a string in C#?


Let us first set an array of 5 characters −

char[] ch = new char[15];
ch[0] = 'T';
ch[1] = 'r';
ch[2] = 'i';
ch[3] = 'c';
ch[4] = 'k';

Now convert them into a string −

string str = new string(ch);

Here is the complete code −

Example

Using System;
class Program {
   static void Main() {
      char[] ch = new char[15];
      ch[0] = 'T';
      ch[1] = 'r';
      ch[2] = 'i';
      ch[3] = 'c';
      ch[4] = 'k';
      // converting to string
      string str = new string(ch);
      Console.WriteLine(str);
   }
}

Updated on: 22-Jun-2020

127 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements