How do I convert array of char to string?

Category: System, viewed: 1544 time(s).

This example demonstrate how to convert value of char[] (array of characters) into an instance of string object.

using System;

namespace Kodecsharp.Example.System
{
    public class CharArrayToString
    {
        public static void Main(string[] args)
        {
            char[] data = new char[10];
            data[0] = 'a';
            data[1] = 'b';
            data[2] = 'c';
            data[3] = 'd';
            data[4] = 'e';
            data[5] = 'f';
            data[6] = 'g';
            data[7] = 'h';
            data[8] = 'i';
            data[9] = 'j';

            //
            // Initialize a new instance of the System.String class to the 
            // value indicated by an array of unicode characters.
            //
            string abc = new string(data);

            Console.WriteLine(abc);
        }
    }
}
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Our Friends

Network Sites

Statistics

Locations of visitors to this page