Generic Dispose Function?

From: Jeff (a_at_a.com)
Date: 03/22/04


Date: Mon, 22 Mar 2004 07:12:59 -0700

In C++ I used to declare the following macro for deleteing objects:

#define SAFEDELETE(x) if(x != NULL) { delete x; x = NULL; }

Is there currently a way to do something similar to this in C#?

I'm constantly writing...

if(x != null)
{
    x.Dispose();
    x = null;
}

and would love to just write something like...

SAFEDISPOSE(x);

Thanks for your help!



Relevant Pages

  • Re: Declaring Objects
    ... What this is saying is set the Colors variable to refer to the Colors sheet, ... > that I need to declare my objects and know that I would prefer to declare ... > Below is my first attempt to writing a macro, ... > Sub FindAndReplace() ...
    (microsoft.public.excel.programming)
  • Re: Converting C to Delphi
    ... macro and a million constants. ... Can this be imported into delphi or do I ... > Perform those calculations yourself and declare the constants with the ... One is temp, ...
    (alt.comp.lang.borland-delphi)
  • Re: Loop problem
    ... (declare (special a b)) ... will need a macro to type in the nest of dolists for you. ... The macroexpander will say "Oh I'm not finished yet." ...
    (comp.lang.lisp)
  • Re: VBA Word 2003 File Close
    ... It would be better to declare a variable as a Document and set that variable to the document that you are opening rather than rely on the active document. ... In a Word 2003 template document I have a macro triggered by a CheckBox ... document and then is supposed to close that second document. ... I get a run-time error 4198 "Command Failed" at the line that ...
    (microsoft.public.word.vba.general)
  • Re: one simple question
    ... You'll most likely find a macro called NULL in one of the Visual C++ ... this doesn't declare a function. ... Empty brackets would be equivalent to replacing the "null" with "void", ... also making this a function declaration. ...
    (comp.lang.cpp)