Home >Backend Development >C++ >How to Efficiently Convert a char[] to a String in C#?
.NET / C#: Converting char[] to String
The question arises as to how to effectively convert an array of characters (char[]) into a string. The ToString() method used with arrays of characters is insufficient in this case.
To address this issue, the solution lies in utilizing the constructor available specifically for this purpose. For instance:
char[] chars = {'a', ' ', 's', 't', 'r', 'i', 'n', 'g'}; string s = new string(chars);
This approach effectively transforms the char[] array into a string.
The above is the detailed content of How to Efficiently Convert a char[] to a String in C#?. For more information, please follow other related articles on the PHP Chinese website!