Hi,
I have a list of base objects (RTUDevice) and want to iterate through and convert each to a derived object (actually a derived of a derived RTDSensor) , however the downcasting is throwing an error.
public RTUDevice(int id)
{
_id = id;
}
public class RTDDevice : RTUDevice
{
public RTDDevice(int id)
: base(id)
{
}
}
public class RTDSensor : RTDDevice
{
public RTDSensor(int id)
: base(id)
{
}
}
RTDSensor return = (RTDSensor)_devices.Find(d => d.Id == p.ReturnId);
Would it be better to pass the base object in a constructor to RTDSensor like
public RTDSensor(RTUDevice rtu) : base(rtu.Id)
{
}
or is my OOP design way off the mark.