The C# ToCharArray function is utilized to extract a character array from a string instance.
Signature
Example
public char[] ToCharArray()
public char[] ToCharArray(Int32, Int32)
Parameter
The initial function does not require any arguments, whereas the subsequent function accepts two integer parameters.
Return
It returns a character array.
C# String ToCharArray Method Example
Example
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "Hello C#";
char[] ch = s1.ToCharArray();
foreach(char c in ch){
Console.WriteLine(c);
}
}
}
Output:
Output
H
e
l
l
o
C
#