I have an array

Para[] Day = new Para[8]; 

from the structure:

 struct Para //Описываем структуру с полями: { public int para_number; //Номер пары public string para_name; //Название предмета public int room_number; //Номер кабинета public string teacher_name; //Имя преподавателя } 

there is still an array

 Day[] Week = new Day[5]; 

How do I get and set the values ​​of the elements?

For Day[i].para_name; It's clear. But for Week[i].Day[j].para_name it does not work, exactly as for Week[i][j] .

  • First, a multi-line code needs to be indented by four spaces or by pressing the {} button, and not by single quotes. Secondly, you should provide the Day code, otherwise you cannot say what the problem is. - AivanF.
  • @AifanF, edit already sent. - ߊߚߤߘ
  • What does "it does not work" mean? Compile or runtime error? What is the error text? - ߊߚߤߘ
  • And Day[] Week = new Day[5]; you do not give an error? - Mirdin

1 answer 1

You did not correctly declare an array of Week . It really won't work because Day is not a data type, but a variable name, based on the example you gave.

You can fix it as follows:

Use jagged array

 Para[][] Week = new Para[5][]; for(int i = 0; i< Week.Length; i++) { Week[i] = new Para[8]; } Week[0][0] = new Para(...); 

Use two-dimensional array

 Para[,] Week = new Para[5, 8]; Week[0, 0] = new Para(...); 

Explicitly define the class or structure of the Day and use your variation.