I'm using the array length as the test condition in my for loop. But if there is only one element in the array, I receive an 'Index was outside the bounds of the array' error. What am I doing wrong? Thanks.
string templateList;
string[] template;
string sizeList;
string[] size;
templateList = textBox1.Text;
template = templateList.Split(',');
sizeList = textBox2.Text;
size = sizeList.Split(',');
for (int i = 0; i <= template.Length; i++)
{
for (int j = 0; j < size.Length; j++)
{
//do something with template[i] and size[j]
}
}
the values are coming from a textBox, the user may only enter one value. In which case it would only need to run once.