Convert string to char array in c#

186 View    Jan 17 2020 10:44PM

The ToCharArray method of the string class converts a string to a character array. The following code snippet creates a string into a char array.



public char[] ToCharArray()


public char[] ToCharArray(int startIndex, int length)



string sentence = "Mind Spark";  

char[] charArr = sentence.ToCharArray(); 

 foreach (char ch in charArr)  





String: Mind Spark

Character array : M i n d S p a r k