views:

2266

answers:

5

Guess I have just never run across it before.

What is the proper way to turn a char[] into a string?

The ToString() method from an array of chars doesn't do the trick. Guess I had always imagined that was what it was for.

+33  A: 
char[] chars = {'a', ' ', 's', 't', 'r', 'i', 'n', 'g'};
string s = new string(chars);
Joel Coehoorn
+7  A: 

Use the constructor of string which accepts a char[]

char[] c = ...;
string s = new string(c);
JaredPar
+4  A: 
char[] characters;
...
string s = new string(characters);
Austin Salonen
+2  A: 

String mystring = new String(mychararray);

schwartz
A: 

Isn't there a String constructor that takes a char array?

John Nolan