EN
C# / .NET - convert string to character array
0
points
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