for 루프에서 테스트 조건으로 배열 길이를 사용하고 있습니다. 그러나 배열에 요소가 하나만 있으면 '인덱스가 배열의 경계를 벗어났습니다.'오류가 발생합니다. 내가 도대체 뭘 잘못하고있는 겁니까? 감사.for 루프에서 오류를 일으키는 1 요소가있는 배열
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]
}
}
값이 textBox에서 오는 경우 사용자는 하나의 값만 입력 할 수 있습니다. 어떤 경우에는 한 번만 실행하면됩니다.
당신은 아마 더 나은 제공 될 것입니다 ... 사용해야합니다 /ttw7t8t6.aspx). 색인 수학은 실제로 C#에서 시간 낭비입니다. –