Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Can I have an array of methods or is there a better way?
I am writing a program that will hold models and display them when selected. I probably am thinking to complicated but I was planning on writing a method in a class to initialize the model and another to draw the model on screen - I was going to use an array to store the new method instances in when a new model is added.
This is all being done in Visual C# XNA and I created a new form as the control panel.
2 Answers
- RatchetrLv 71 decade agoFavorite Answer
Not sure I'm really following your question, but doesn't standard class inheritance solve this?
class model
{
virtual void Initialze() {}
virtual void Draw() {}
}
class CoolModel1 : model
{
override void Initialize() { /* whatever */ }
override void Draw() { /* do draw stuff */ }
}
class CoolModel2 : model
{
override void Initialize() { /* whatever */ }
override void Draw() { /* do draw stuff */ }
}
If that isn't what you are after, add some more details to the question please.
- Anonymous1 decade ago
It's difficult to understand what you mean because some of your terminology isn't standard
For example, methods don't have instances; and there's no practical way for a class to have an array of methods, since methods are not properties.
All classes do have constructors, which you can use to initially set certain properties of the model.
If what you mean is you want to have a collection of model objects, sure, you can do that. (A collection being an array of similar objects).