split a string into an array of characters in csharp

To split a string into an array of characters in C#, you can use the ToCharArray() method. This method returns an array of characters that make up the string.

Here is an example:

main.cs
string str = "hello";
char[] chars = str.ToCharArray();

foreach (char c in chars)
{
    Console.WriteLine(c);
}
113 chars
8 lines

Output:

main.cs
h
e
l
l
o
10 chars
6 lines

In the example above, we create a string "hello" and then call the string's ToCharArray() method to get an array of characters. We then iterate over each character in the array using a foreach loop and print it to the console.

gistlibby LogSnag