I have three types:
Patient
Inpatient : Patient
Outpatient : Patient
I have a method that fills the base patient and all it's properties: PatientRepository.FillPatient()
and returns a Patient
object.
I then need to check and see what the Patient
type is and downcast to either an Outpatient
or Inpatient
.
When I try to downcast, it is throwing Unable to cast object of type 'Patient' to type 'Inpatient'.
This is a run-time error.
if (patient.Type == PatientType.Inpatient)
{
var inpatient = (Inpatient)patient;
return inpatient;
}
public enum PatientType
{
Inpatient, Outpatient
}
I have no idea why. Am I fundamentally doing something wrong here?