C# String ToCharArray() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

In C#, ToCharArray() copies the characters of a string into a new char[]. Each element of the array is one character, in the same order.

The array is a separate copy. You can change its elements, sort or reverse them, and then build a new string with new string(array). The original string never changes, because strings are immutable but arrays are not. To read characters without copying, simply use the indexer, text[i], or a foreach loop.

This is an instance member of System.String. Call it on a string variable, such as text.ToCharArray(...). Calling it on a null variable throws NullReferenceException. It copies characters to a separate place. Strings are immutable, so changing that copy never changes the original string.

Syntax

Call it with no arguments for all characters, or give a start and a length.

C#
string word = "hello";

char[] all = word.ToCharArray();          // { 'h', 'e', 'l', 'l', 'o' }
char[] part = word.ToCharArray(1, 3);     // { 'e', 'l', 'l' }
string back = new string(all);            // "hello"
CallWhat it does
text.ToCharArray()Copy every character into a new array.
text.ToCharArray(6, 5)Copy 5 characters starting at index 6.
new string(chars)Turn an edited array back into a string.

startIndex and length must stay inside the string, or you get ArgumentOutOfRangeException. An empty string gives an empty array (length 0). For copying into an array you already have, see CopyTo().

Library declarations
C#
public char[] ToCharArray();
public char[] ToCharArray(int startIndex, int length);

Parameters

ParameterDescription
startIndexOptional. The first character to copy.
lengthOptional. How many characters to copy.

Return Value

Return ValueDescription
char[]A new array holding a copy of the characters.

C# Examples

Example 1 — Turn a Word into Characters

Copy a word into an array, then read its length and a few elements.

C#
using System;

class Program {
    static void Main() {
        char[] letters = "hello".ToCharArray();

        Console.WriteLine(letters.Length);
        Console.WriteLine(letters[0]);
        Console.WriteLine(letters[4]);
    }
}

How It Works

  1. One element per character. "hello" has five characters, so the array has five elements.
  2. Same order. Index 0 holds 'h', just like in the string.
  3. The last element. Index 4 (length minus one) holds 'o'.
  4. A real array. letters is an ordinary char[]; you can pass it to any method that takes an array.

Example 2 — Reverse a String

Strings cannot be reversed in place, but an array can. Copy, reverse, and rebuild.

C#
using System;

class Program {
    static void Main() {
        string word = "stressed";
        char[] arr = word.ToCharArray();

        Array.Reverse(arr);
        string reversed = new string(arr);

        Console.WriteLine(reversed);
        Console.WriteLine(word);
    }
}

How It Works

  1. Copy into an array. ToCharArray() gives a version of the word that can be changed.
  2. Reverse in place. Array.Reverse(arr) swaps the elements so the last character comes first.
  3. Back to text. new string(arr) creates desserts from the reversed characters.
  4. Two separate strings. word still reads stressed; the array was a copy.

Example 3 — Change One Letter and Copy a Range

Swap the first letter of a word through the array, then copy just one word out of a phrase.

C#
using System;

class Program {
    static void Main() {
        string word = "cat";
        char[] chars = word.ToCharArray();
        chars[0] = 'b';

        Console.WriteLine(word);
        Console.WriteLine(new string(chars));

        char[] part = "Hello World".ToCharArray(6, 5);
        Console.WriteLine(new string(part));
    }
}

How It Works

  1. Arrays can change. chars[0] = 'b' is allowed, while word[0] = 'b' would not even compile.
  2. The string ignores it. word still prints cat, because the array is an independent copy.
  3. Rebuild to see the change. new string(chars) turns the edited array into bat.
  4. Copy a slice. ToCharArray(6, 5) copies five characters from index 6, which spell World.

Frequently Asked Questions

It returns a new char array with a copy of the string's characters, in the same order.
No. The array is a copy. Strings are immutable, so you need new string(array) to get the changed text.
Use new string(chars). For part of the array, use new string(chars, startIndex, length).
Copy it with ToCharArray(), call Array.Reverse on the array, and create a new string from it. Note that this reverses UTF-16 chars, which can split emoji.
No. You can use foreach (char c in text) or text[i] directly. Use ToCharArray when you need a separate array you can change.

Next: ToLower()

Get a lowercase copy of a string using the current (or a chosen) culture.

ToLower() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful