我有一个锯齿阵列来获取学生和主题的详细信息,我使用了2个锯齿阵列,一个用于学生的详细信息(名称和rollno),另一个用于主题的详细信息(主题和标记),现在我想总结一下特定学生的所有标记,谁能告诉我怎么去解决这个问题,下面是我的整个代码。在锯齿阵列中总结数值
public void GetStudentDetails()
{
Console.WriteLine("Please enter number of Students");
int STUDENTS = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please enter number of Subjects");
int SUBJECTS = Convert.ToInt32(Console.ReadLine()); //0 is reserved for the student name, so the marks starts from the index 1, hence if you set the marks for 3, it will ask for 2 marks
string[][] student_details = new string[STUDENTS][];
string[][] subject_details = new string[SUBJECTS][];
string[][] result_details = new string[STUDENTS][];
StringBuilder stud_sub_info = new StringBuilder();
stud_sub_info.Append("Name\tRoll-No\t");
for (int a = 0; a < STUDENTS; a++)
{
student_details[a] = new string[STUDENTS * 2];
for (int b = 0; b < 2; b++)
{
Console.WriteLine("Enter Student {0} {1}:", a + 1, (b == 0) ? "Name" : "Roll-No");
student_details[a][b] = Console.ReadLine();
}
for (int c = 0; c < SUBJECTS; c++)
{
subject_details[c] = new string[SUBJECTS * 2];
for (int d = 0; d < 2; d++)
{
if (d == 0)
{
Console.WriteLine("Enter Name for Subject {0}", c + 1);
subject_details[c][d] = Console.ReadLine();
stud_sub_info.Append(subject_details[c][d] + "\t");
}
else
{
Console.WriteLine("Enter Marks for {0}", subject_details[c][d - 1]);
subject_details[c][d] = Console.ReadLine();
}
}
}
}
Console.WriteLine(stud_sub_info.ToString());
for (int a = 0; a < STUDENTS; a++)
{
for (int b = 0; b < 2; b++)
{
Console.Write(student_details[a][b] + "\t");
}
for (int c = 0; c < SUBJECTS; c++)
{
for (int d = 0; d < 2; d++)
{
Console.Write(subject_details[c][d] + "\t");
}
}
}
}
尽管需要稍微修改student_details [STUDENT * 2]和subject_details [SUBJECT * 2],在这两种情况下(* 2)都不是必需的,因为它会在数组中创建空白索引,所有其他代码都会休眠很好,最好的部分是它的整洁,然后我的 – Abbas