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
Posted Jun 16, 2008, 4:00 AM
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
dzeidzeiPosted Jun 16, 2008, 12:56 AM
Thaks for Your answers.
-dzeidzei
Bechir BejaouiPosted Jun 14, 2008, 6:01 AM
Scott LyslePosted Jun 14, 2008, 1:10 AM