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#.
The following example shows how to obtain a character array from a string instance using the ToCharArray()
method.
xxxxxxxxxx
1
using System;
2
3
public class Program
4
{
5
public static void Main(string[] args)
6
{
7
string sampleString = "Sample text";
8
char[] charArray = sampleString.ToCharArray();
9
10
foreach (char charElement in charArray)
11
{
12
Console.WriteLine(charElement);
13
}
14
}
15
}
Output:
xxxxxxxxxx
1
S
2
a
3
m
4
p
5
l
6
e
7
8
t
9
e
10
x
11
t