Hi,
I have application with couple of classes. One class is named CpriorStart containing strings as members for storing data.
Then I have other class named CstartingHorse, having string members as well, but it also contains array for previously mentioned CpriorStart objects. I allocate that array in constructor as follows:
public
class CstartingHorse{
private CpriorStart[] previousStarts;
public CstartingHorse()
{
previousStarts = new CpriorStart[8];
}
}
So, do I need a destructor in that CstartingHorse class and if positive, what to do in it?
I also have third class named Crace containing again strings as members. It also contains arraylist member for storing previously mentioned CstartingHorse objects. That arraylist is also allocated in constuctor like:
alStartingHorses =
new ArrayList();If I've got it right, I don't need destructor for this class. Or do I? And again, if positive, what to do in destructor?
Thanks!
-dzeidzei

Scott LysleRank #49 · 31K reputationPosted Jun 13, 2008, 9:10 PM EDT
Bechir BejaouiRank #144 · 15.9K reputationPosted Jun 14, 2008, 2:01 AM EDT
dzeidzei3 reputationPosted Jun 15, 2008, 8:56 PM EDT
Thaks for Your answers.
-dzeidzei
Posted Jun 16, 2008, 12:00 AM EDT
Firstly there are no destructors in C#. There are finalizers in C# but they aren't the same. In response to your question you should think about how you build things. For example setting up a Christmas tree.
However when you take it down it goes in reverse.
Same thing with objects. A derived class can rely on base class members therefore the base class must be around as long as the derived class is. During construction this means the base class must be initialized first. During destruction the base class must be the last to go. Hence the base-to-derived construction and derived-to-base finalization
for further u can verify this link
http://msdn.microsoft.com/en-us/library/66x5fx1b(VS.80).aspx