I've got this in my code, that is, we're inside a class called Patient,
so a Patient can have Appointments:
private IList<Appointment> _appointments = null;
public IList<Appointment> Appointments
{
get
{
if (_appointments == null)
{
RetrievePatientAppointments();
}
return _appointments;
}
set
{
_appointments = value;
}
}
The "RetrievePatientAppointments" method queries database, obtains
records and tries to add Appointment objects in a foreach bucle. The
pain is that when it is bound to add an Appointment, fails, because it
is null (The initialization of the IList is to null if you see).
How could I avoid IList being null? How to initialize it?