Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET / C# - Convert char[] to string

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

The ToString() method from an array of characters doesn't do the trick.

like image 228
BuddyJoe Avatar asked Aug 24 '09 18:08

BuddyJoe


2 Answers

There's a constructor for this:

char[] chars = {'a', ' ', 's', 't', 'r', 'i', 'n', 'g'}; string s = new string(chars); 
like image 182
Joel Coehoorn Avatar answered Sep 17 '22 22:09

Joel Coehoorn


Use the constructor of string which accepts a char[]

char[] c = ...; string s = new string(c); 
like image 28
JaredPar Avatar answered Sep 18 '22 22:09

JaredPar