Languages
[Edit]
EN

C# / .NET - convert string to character array

0 points
Created by:
Pearl-Hurley
559

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
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

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