HiveBrain v1.2.0
Get Started
← Back to all entries
snippetcsharpCritical

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

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
netstringconvertchar

Problem

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.

Solution

There's a constructor for this:

char[] chars = {'a', ' ', 's', 't', 'r', 'i', 'n', 'g'};
string s = new string(chars);

Code Snippets

char[] chars = {'a', ' ', 's', 't', 'r', 'i', 'n', 'g'};
string s = new string(chars);

Context

Stack Overflow Q#1324009, score: 886

Revisions (0)

No revisions yet.