Convert character array to string in C# 

In this article we will discuss about how to convert character array to string in C#.
  • 5223

In the following example character array is converted into string. Here character array is declared and assigned the values and then converted into string using string s=new string (ch) statement.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] ch = new char[15];
            ch[0] = 'O';
            ch[1] = 'n';
            ch[2] = 'l';
            ch[3] = 'y';
            ch[4] = ' ';
            ch[5] = 'T';
            ch[6] = 'h';
            ch[7] = 'e';
            ch[8] = ' ';
            ch[9] = 'P';
            ch[10] = 'e';
            ch[11] = 'r';
            ch[12] = 's';
            ch[13] = 'o';
            ch[14] = 'n';
            string s = new string(ch);
            Console.WriteLine(s);
            Console.ReadLine();
        }
    }
}

 


Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.