You cannot, because .NET uses like java a nondeterministic garbage
collector, which means the system does *not* know when exactly your objects
are go out of scope. It inspects sometimes all objects if they are still
reachable, and sweep away the rest.
But you can provide a finalizer (a destructor in C#) which will be called
when an object is *collected*. Though there are some things pay attention to
and you should rarely use finalizer as they affect negatively your programs
performance.
--
cody
Freeware Tools, Games and Humour
http://www.deutronium.de.vu ||
http://www.deutronium.tk
"Paul Wilkinson" <pw********@mail.com> schrieb im Newsbeitrag
news:54**************************@posting.google.c om...
How can I write a method that is called when an object goes out of
scope? I've looked all over, so far I've only found discussions of how
to write methods that don't = )