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

BuddyJoe picture BuddyJoe · Aug 24, 2009 · Viewed 384.2k times · Source

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.

Answer

Joel Coehoorn picture Joel Coehoorn · Aug 24, 2009
char[] chars = {'a', ' ', 's', 't', 'r', 'i', 'n', 'g'};
string s = new string(chars);