Languages
[Edit]
EN

C# / .NET - convert string to character array

0 points
Created by:
Pearl-Hurley
369

In this article, we would like to show you how to convert a string to a character array in C#.

Practical example

The following example shows how to obtain a character array from a string instance using the ToCharArray() method.

using System;

public class Program
{
    public static void Main(string[] args)
    {
        string sampleString = "Sample text";
        char[] charArray = sampleString.ToCharArray();

        foreach (char charElement in charArray)
        {
            Console.WriteLine(charElement);
        }
    }
}

Output: 

S
a
m
p
l
e

t
e
x
t

C# / .NET - String (popular problems)

C# / .NET - convert string to character array
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join