string to char array Converting in c#

 Admin   
169 View    Jan 17 2020 11:25PM

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.

Syntax:

 

public char[] ToCharArray()

or

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

 

 

string sentence = "CsharpMonster";  

char[] charArr = sentence.ToCharArray(); 

 foreach (char ch in charArr)  

{

   Console.WriteLine(ch);  

}   

Output:

String: Mind Spark

Character array : C s h a r p M o n s t e r