Home >Backend Development >C++ >How to Efficiently Convert a char[] to a String in C#?

How to Efficiently Convert a char[] to a String in C#?

Patricia Arquette
Patricia ArquetteOriginal
2025-01-04 09:24:34231browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn