我在這裏做錯了什麼,會使index = -1
?當我將索引設置爲只有> 0
時,它將只返回時間數組中的最後一個元素,而不管輸入的字母。爲什麼範圍匹配循環會錯過邊界條件?
char[] lastNameLetterArr = { 'a', 'e', 'j', 'p', 't' };
string[] timeSlotArr = { TIME5, TIME1, TIME2, TIME3, TIME4 };
int index;
index = lastNameLetterArr.Length - 1;
while (index > 0 && lastNameLetterCh < lastNameLetterArr[index])
--index;
timeStr = timeSlotArr[index];
TIMESTR已被宣佈爲在【什麼是IndexOutOfRangeException代碼 – bloop
可能的複製一個字符串變量較早,我該怎麼辦修復它?](http://stackoverflow.com/questions/20940979/what-is-indexoutofrangeexception-and-how-do-i-fix-it) –
@MarkM在代碼中聲明的一個字符變量。這個變量拉動學生姓的第一個字母,當在上面的數組中搜索時,應該通過timeStr變量輸出一個時間片 – bloop