Failed to sum splited text

Posted by user1784753 on Stack Overflow See other posts from Stack Overflow or by user1784753
Published on 2012-12-09T10:20:12Z Indexed on 2012/12/09 11:08 UTC
Read the original article Hit count: 146

Filed under:

I have a problem when summing all of bx3.text to t2.text. first I split bx3.text with space

    private void total()
    {
        string[] ps = bx3.Text.Split(new string[] {" "}, StringSplitOptions.None );
        t2.Text = ps.Select(x => Convert.ToInt32(x)).Sum().ToString();
    }

I did try with t2.text = ps[1] and the number showed was correct. but when i try to sum it all, I got error

"Input string was not in a correct format" on (x => Convert.ToInt32(x))

bx3.text is full of user-input number separated by single space " "

© Stack Overflow or respective owner

Related posts about c#