How to use the String.ToCharArray method to convert a string into an array of chars in C#

1 Answer

0 votes
using System;

class ToCharArray_CSharp {
    public static void Main(string[] args) {
        string s = "c# pro";

        char[] charr = s.ToCharArray();

        foreach (char ch in charr) {
            Console.WriteLine(ch);
        }
    }
}



/*
run:

c
#
 
p
r
o

*/

 



answered Nov 19, 2024 by avibootz
...