Hey all,
I'm having trouble with a piece of C#. I have code which as far as I am aware works correctly in distinguishing whether an object is of the base class, or one of its two child classes. However in another part of the program the conditions of class are never being met.. I have this:
Thing is neither of the ifs are ever satisfied and all instansiations come out as objects of the base class. Help!
I'm having trouble with a piece of C#. I have code which as far as I am aware works correctly in distinguishing whether an object is of the base class, or one of its two child classes. However in another part of the program the conditions of class are never being met.. I have this:
Code:
foreach (Booking c in myCamp.camp)
{
string line = "Booking: " + c.week+" " + c.name + " " + c.address + " " + c.children;
if (c.GetType() == typeof(Activity))
{
Activity a = (Activity)c;
line = line + a.kind + "dave " + a.U16;
}
if (c.GetType() == typeof(Cruise))
{
Cruise b = (Cruise)c;
line = line + b.bora;
}
lstBookings.Items.Add(line);
}
Thing is neither of the ifs are ever satisfied and all instansiations come out as objects of the base class. Help!