First, I create base class and inherited class
public class Entity
{
public int EntityID;
public EntityType type = EntityType.NONE;
}
public class EntityObject : Entity
{
public Vector2 position;
public EntityObject()
{
position = Vector2.Zero;
type = EntityType.OBJECT;
}
}
And then I create list of base class to store all inherited class
List<Entity> entityList = new List<Entity>();
entityList.Add(new EntityObject());
Later, I try to access a member of inherited class in list
for(int i = 0; i < entityList.Count; i++)
if(entityList[i].type == EntityType.OBJECT)
entityList[i].position = Vector2.One;
Yeah, I got an error : 'Entity' does not contain a definition for 'position'and no extension method 'position' accepting a first argument of type 'Entity' could be found (are you missing a using directive or an assembly reference?)
Is there a probably way to access inherited class properties from list of base class?