RAII and C#

Daniel wrote:

I’ve been reading your blog for quite some time, and, while I love C#, I never understood why it doesn’t support RAII (Resource Acquisition Is Initialization). You know, in C++ you can acquire some resource (a handle, a file, a connection) on the class constructor and have it predictably disposed on the class destructor.

Brian Harry wrote a great post on this a couple of years ago


Comments (3)

  1. Claus says:

    What is wrong with using C#’s Finalizer mechanisms?


  2. Cronan says:

    It’s not deterministic.

  3. William says:

    It is when you make use of "using". Not perfect, since a "dumb" programmer can "abuse" the system and create bugs, but it is good enough for the rest of us.