tags:

views:

66

answers:

3

if i have this code, how can i put alle the chars in my string in to the Char array?

i know this wont compile but the logic shows what im trying to do.

    private void button1_Click(object sender, EventArgs e)
    {
        string stringX = textbox1.Text;

        int strlen = stringX.Length();

        char[] arrayX = new char[strlen];

        arrayX = stringX.Split("");    
    }
+4  A: 

Just use the ToCharArray method

private void button1_Click(object sender, EventArgs e)
{
    string stringX = textbox1.Text;

    char[] arrayX = stringX.ToCharArray();    
}
Bob
great, thx for that mate.
Darkmage
No problem, glad to help.
Bob
Bear in mind you can access the characters of a string by index using `stringX[i]`, so creating a new char array is often unnecessary.
Matt Howells
A: 
char[] arrayX = textbox1.Text.ToCharArray();
Peter
A: 

How about

stringX.ToCharArray()
EricSchaefer