C# program to convert list of characters to string

PHPz
Release: 2023-08-22 11:08:38
forward
888 people have browsed it

C# program to convert list of characters to string

First, declare the character array and set the value of each character−

char[] ch = new char[5];

ch[0] = 'H';
ch[1] = 'e';
ch[2] = 'l';
ch[3] = 'l';
ch[4] = 'o';
Copy after login

Now, use the string class constructor and create a new string from the above array of characters −

string myChar = new string(ch);
Copy after login

Example

Let us see the code to convert a list of characters to string in C#.

Live Demo

using System;
namespace Demo {
   class MyApplication {
      static void Main(string[] args) {
         char[] ch = new char[5];
         ch[0] = 'H';
         ch[1] = 'e';
         ch[2] = 'l';
         ch[3] = 'l';
         ch[4] = 'o';
         string myChar = new string(ch);
         Console.WriteLine("Converted to string = {0}", myChar);
      }
   }
}
Copy after login

Output

Converted to string = Hello
Copy after login

The above is the detailed content of C# program to convert list of characters to string. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template