Thursday, 22 August 2013

Using an overridden property in base class

Using an overridden property in base class

I have the following:
class Info
{
public string str;
};
class CarInfo : Info {}
class InfoContainer
{
public virtual List<Info> info_list {get; set;}
public bool is_known(Info inf)
{
if (-1 == info_list.FindIndex( i => i.str == inf.str) return false;
return true;
}
}
class CarFleetInfo : InfoContainer
{
new public List<CarInfo> info_list;
CarFleetInfo()
{
info_list = new List<CarInfo>();
}
}
Main()
{
CarInfo c = new CarInfo();
Info i = new Info();
c.is_known(i);
}
I have few other "specific info" class that inherited from Info (like
CarInfo ), and few classes that inherited from InfoContainer, which are
each overrides info_list with other a list of object of some "specific
info".
now, the call to c.is_known(i) raise an exception saying info_list is null.

No comments:

Post a Comment