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

CsharpProgrammingServer Side Programming

Firstly, set the characters.

char[] arr = new char[5];
arr[0] = 'Y';
arr[1] = 'E';
arr[2] = 'S';

Now, convert them into string.

string res = new string(arr);

The following is the complete code to convert a list of characters into a string −

Example

 Live Demo

using System;

class Program {
   static void Main() {
      char[] arr = new char[5];
      arr[0] = 'Y';
      arr[1] = 'E';
      arr[2] = 'S';

      // converting to string
      string res = new string(arr);

      Console.WriteLine(res);
   }
}

Output

YES
raja
Published on 20-Aug-2018 10:14:02
Advertisements