C#
.NET
char array
string conversion
programming tutorial

.NET / C - Convert char to string

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

In C#, converting a char to a string is simple, but the exact method depends on whether you have a single character or a full char[]. Many short answers blur those two cases together, which is why developers sometimes reach for the wrong API.

Convert a Single char

For one character, the most direct approach is ToString():

csharp
1using System;
2
3char letter = 'A';
4string text = letter.ToString();
5
6Console.WriteLine(text);
7Console.WriteLine(text.GetType().Name);

This produces a new string containing exactly one character. It is readable, idiomatic, and usually the best choice when you already have a char.

Another valid option is Convert.ToString(letter):

csharp
1using System;
2
3char symbol = '#';
4string text = Convert.ToString(symbol);
5
6Console.WriteLine(text);

That is useful when you are already writing conversion-heavy code and want a uniform style, but for a plain char, ToString() is usually clearer.

Create a string from a char[]

If the input is a character array, use the string constructor:

csharp
1using System;
2
3char[] letters = { 'H', 'e', 'l', 'l', 'o' };
4string word = new string(letters);
5
6Console.WriteLine(word);

This is a different problem from converting a single char. The constructor copies the contents of the array into a new immutable string.

You can also build a string from part of an array:

csharp
1using System;
2
3char[] letters = { 'C', '#', ' ', '8', '.', '0' };
4string version = new string(letters, 3, 3);
5
6Console.WriteLine(version);

That example prints 8.0 by starting at index 3 and taking three characters.

When string.Concat Is Appropriate

string.Concat also works with char[]:

csharp
1using System;
2
3char[] chars = { 'W', 'o', 'r', 'l', 'd' };
4string result = string.Concat(chars);
5
6Console.WriteLine(result);

This is valid, but it is usually less explicit than new string(chars) when the source is already a character array. The constructor communicates intent better: you are creating a string from characters, not concatenating several separate values.

Understand Immutability

A key detail in .NET is that strings are immutable. Changing the original array after conversion does not change the string you created:

csharp
1using System;
2
3char[] chars = { 'c', 'a', 't' };
4string animal = new string(chars);
5
6chars[0] = 'b';
7
8Console.WriteLine(animal);
9Console.WriteLine(new string(chars));

The first Console.WriteLine still prints cat. The second prints bat. This matters when you work with buffers, parsers, or security-sensitive code where mutable character data and immutable strings behave differently.

Converting While Parsing Input

A common real-world case is walking through a string or buffer one character at a time and selectively turning characters into strings for formatting or APIs that only accept string:

csharp
1using System;
2
3string source = "A1B2";
4
5foreach (char ch in source)
6{
7    if (char.IsLetter(ch))
8    {
9        string token = ch.ToString();
10        Console.WriteLine($"letter: {token}");
11    }
12}

This is clearer than wrapping each character in a one-element array just to call the string constructor.

Special Characters Work the Same Way

Escape characters are still ordinary char values and can be converted the same way:

csharp
1using System;
2
3char newline = '\n';
4string text = newline.ToString();
5
6Console.WriteLine(text.Length);
7Console.WriteLine((int)text[0]);

The resulting string has length 1 even though printing it may look unusual because the character controls formatting.

Common Pitfalls

  • Mixing up a single char with a char[] and using new string(value) on the wrong type.
  • Using string.Join for simple character conversion, which adds unnecessary complexity.
  • Forgetting that strings are immutable and expecting later char[] changes to affect the created string.
  • Creating one-element arrays just to convert a single character when ToString() is simpler.
  • Misreading special characters such as '\n' or '\t' because their output affects the console display.

Summary

  • Use charValue.ToString() for a single char.
  • Use new string(charArray) when the input is a char[].
  • Prefer the string constructor over string.Concat when converting a character array directly.
  • Remember that the resulting string is immutable and independent from the original array.
  • Choose the API that matches the actual input type instead of treating char and char[] as the same problem.

Course illustration
Course illustration

All Rights Reserved.