You can't. However, you can replace the array with a new one which contains the extra element.
But it is easier and gives better performance to use an List<T>
(uses interface IList
) for this. List<T>
does not resize the array every time you add an item - instead it doubles it when needed.
Try:
class Student
{
IList<Subject> subjects = new List<Subject>();
}
class Subject
{
string Name;
string referenceBook;
}
Now you can say:
someStudent.subjects.Add(new Subject());