Link to home
Start Free TrialLog in
Avatar of daveamour
daveamourFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Dispose

When I write classes in C# then implement them as follows:

ETrainingDemo.Classes.NewsLetterRecipient objRecipient = new ETrainingDemo.Classes.NewsLetterRecipient();

objRecipient.Firstname = Firstname.Text;
objRecipient.Surname = Surname.Text;
objRecipient.Email = Email.Text;
objRecipient.Add()

If I want to kill the object straight away rather than relying on the garbage collector, what is the best way to do this.  Is there a command like Set object = Nothing?  Should I build dispose code into my class, should I inherit a Dispose Interface?

Any thoughts, ideas please?

Thanks

Dave
ASKER CERTIFIED SOLUTION
Avatar of iamtsubasa
iamtsubasa

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of daveamour

ASKER

Thanks, that all makes sense and is a great help.  How do I overide the destructor though?  I'm not really sure what this means.

Thanks

Dave
Avatar of iamtsubasa
iamtsubasa

Sorry for confusing...
Not really overriding it.  Just implement the destructor like this would do it:

~NewsLetterRecipient()
{
    Dispose();
}

Regards.
Ok, thanks very much :)