학생 및 주제 세부 정보를 얻기 위해 지그재그 배열이 있습니다. 학생 세부 정보 (이름 및 롤로)와 대상 세부 정보 (제목 및 표시)에 대해 각각 2 개의 지그재그 형 배열을 사용했습니다. 이제는 특정 학생의 모든 점수를 합산하기를 원합니다. 누군가가 어떻게 저에게 갈 수 있는지 알려줄 수 있습니까? 아래는 제 전체 코드입니다.들쭉날쭉 한 배열의 값을 합산합니다.
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