After a lot of comments, I'm so glad finally we learn what is the error and which line gets it.
But I'm still suspect about your splitValues[i]
is " "
or ""
. Anyway, I try to answer both case.
If your splitValues[i]
is ""
, that means one of your array value is empty string after that line;
string[] splitValues = textBox1.Text.Split(',');
In this case, you can use StringSplitOptions.RemoveEmptyEntries
enumeration like;
string[] splitValues = textBox1.Text.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
If your splitValues[i]
is " "
, then you need to replace your spaces in your string with String.Replace
method like;
string[] splitValues = textBox1.Text.Replace(" ", "").Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);