I am a beginner in C# and I would like to know how to convert strings to chars, specifically string[]
to char[]
. I tried ToCharArray()
, but I then I got an error saying that it doesn't exist. Convert.ToChar(<char here>)
gives me a error saying
cannot convert from "char" to "System.Array"
Use:
string str = "Hello"; char[] characters = str.ToCharArray();
If you have a single character string, You can also try
string str = "A"; char character = char.Parse(str); //OR string str = "A"; char character = str.ToCharArray()[0];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With