こんにちは私は成績計算に取り組んでいます。ここでの問題は、文字列配列の長さが int 配列よりも長い場合、最後の 2 学年をスキップして機能することです。元:
int[] unit = new int[] {1,-3,3,4};
string[] letter_grade = new string[] {"A", "B","B","W","D","F"};
ただし、文字列配列の長さよりも長い int 配列の長さが機能しない場合、エラーがスローされ、インデックスが配列の境界外にありました。
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
}
}