라인 yearList.SetValue (years [count], count);에서 경계 외부 예외를 던지고있는 내 프로그램에 다음 코드가 있습니다.C에서 인덱스 범위를 벗어난 예외 #
protected void invoiceYear_DataBound(object sender, EventArgs e)
{
//invoiceYear.SelectedItem.Value= GetYearRange();
String[] years = GetYearRange().Split(new char[] { '[', ',', ']',' ' });
ListItem [] yearList = new ListItem[]{};
System.Diagnostics.Debug.WriteLine("years-->" + years.Length);
for (int i = 0; i < years.Length; i++)
{
System.Diagnostics.Debug.WriteLine("years-->" + years.GetValue(i));
}
int count = 0;
foreach (String str in years)
{
if (string.IsNullOrEmpty(str))
System.Diagnostics.Debug.WriteLine("empty");
else
{
yearList.SetValue(years[count], count);
count++;
}
}
//System.Diagnostics.Debug.WriteLine("yearList-->" + yearList.GetValue(0));
//invoiceYear.Items.AddRange(yearList);
}
실제로 질문하지 않았습니다. 질문을 포함하도록 소식을 업데이트하고 싶을 수도 있습니다. –
* years * 배열에 액세스 할 때 ** count ** 값을 확인하려면 디버깅을 시도 했습니까? –
count -1을 시도해보십시오. –