嗨,我正在研究成绩计算。我的问题是,如果字符串数组的长度比 int 数组长,它可以跳过最后 2 个等级。前任:
int[] unit = new int[] {1,-3,3,4};
string[] letter_grade = new string[] {"A", "B","B","W","D","F"};
但是如果 int 数组的长度比字符串数组的长度长,则它的抛出错误 Index 超出了数组的范围。
int[] unit = new int[] {1,-3,3,4,5,6,7};
string[] letter_grade = new string[] {"A", "B","B"};
所以我的问题是如何让它对两者都有效?
int length = unit.Length;
int no_units = length;
double totalGrade_Points = 0.0;
int totalno_units = 0;
totalGPA = 0;
for (int i = 0; i < unit.Length; i++)
{
entrygot = findGpaListentry(letter_grade[i]); //Index was outside the bounds of the array.
if (entrygot != null)
{
//some code calculation
}
}