In previous article, I mentioned How to convert string to int in C#?  and Create GUID in C# (Various examples) but now in this article, I have mentioned how you can easily convert string to char array in C# using .ToCharArray() and Char.Parse using Console application example.

Convert string to array using .ToCharArray() in C#

So, C# have inbuilt method .ToCharArray() which will return character convert when used on string, so if you have multiple characters string, and you want whole string into an array of characters, then you can use this method.

.ToCharArray() is called on string and return characters of an array, let's take a look on C# console application example below

using System;

public class Program
{
    public static void Main()
    {
        // Input string.
        string value = "testing";
        
        // Use ToCharArray to convert string to array.
        char[] array = value.ToCharArray();
        
        // Loop through array.
        for (int i = 0; i < array.Length; i++)
        {
            // Get character from array.
            char letter = array[i];
            // Display each character.
            Console.WriteLine("Letter: " + letter);
        }
    }
}

Output:

Letter: t
Letter: e
Letter: s
Letter: t
Letter: i
Letter: n
Letter: g

string-to-char-array-using-csharp

Try it on fiddle: https://dotnetfiddle.net/LyJwN2

Convert string to char using char.Parse in C#

If you want to convert a single character string into char aray then you can use char.parse method, it takes a string that contains a single character and Converts the value of the specified string to its equivalent Unicode character.

Example:

using System;

public class ParseSample {
    public static void Main() {
        string input = "B";
        Console.WriteLine(Char.Parse(input)); // Output: 'B'
    }
}

Output:

B

As you can see in the above method, we converted single char string into char in C#, but this method is not usefule, when we have more than 1 character in string.

Convert string to char using string[index] in C#

We can also target specific index element of a string and convert it into char using C#, as shown in below example

            string str = "hello";
            char c = str[0];
            Console.WriteLine(c); // output 'h'

In the above code, str[0] value = "h", basically, first character of string is "h" in theabove "str".

That's it, hope it helps.

You may also like to read:

Serialization & Deserialization in C# With Console application example

Multithreading in C# (With example)

File I/O in C# (Read, Write, Delete, Copy file using C#)

File upload using Ajax in ASP.NET Core

What is full stack web-development and it's advantage