I have one main class with several inherited members who all overload the same Draw method of the parent class, but have different Initialize methods. Is it somehow possible to use the same list type for every inherited class, and thus be able to iterate through the Draw-methods? I am pretty sure you can do this with templates in C++, but can’t seem to find a way to do it in C#. Here is an example:
class MainMenu : ExpandingWindow{
Init(A,B)
Draw(D)
}
class SideMenu : ExpandingWindow{
Init(A,B,C)
Draw(D)
}
I want to be able to do:
WindowList List<ExpandingWindow>
WindowList.Add(new MainMenu)
WindowList.Add(new SideMenu)
WindowList[0].Initialize(A,B)
WindowLIst[1].Initialize(A,B,C)
And:
for each window in WindowList{
window.Draw(D)
}
I am pretty sure I’m missing something here. I do not have to do it in this exact manner, I am rather looking for general way of handling these situations well.
Thanks!
Try: