Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type casting question

foreach(PlayerBase p in Members)
{
    p.Render();
}

The Members list contains members of type FieldPlayer or GoalKeeper. FieldPlayer and GoalKeeper inherit from PlayerBase. When I call p.Render(), I need the appropriate Render call to be called for FieldPlayer or GoalKeeper. How do I do that?

Thanks

like image 805
pokoko222 Avatar asked Dec 28 '22 14:12

pokoko222


1 Answers

You make the PlayerBase.Render method virtual. See this question for more information.

like image 193
Jon Avatar answered Dec 30 '22 11:12

Jon