How do I convert array of char to string?
Category: System, viewed: 4K 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);
}
}
}