Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to convert a list of characters into a string
Firstly, 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';
Now, use the string class constructor and create a new string from the above array of characters −
string myChar = new string(ch);
Example
Let us see the code to convert a list of characters to string in C#.
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);
}
}
}
Output
Converted to string = Hello
Advertisements