Groups | Blog | Home
all groups > dotnet framework > december 2007 >

dotnet framework : Use of idisposable interface.


Archana
12/26/2007 11:06:17 PM
Hi all,

Can anyone tell me exact use of idisposable interface.

I read that to release unmanages resources its better to implement
idisposable interface and call its dispose method.

But what if without implementating interface idisposable i write
method dispose and call that method to release unmanaged resources.

Please correct me if i am wrong.

Jack Jackson
12/26/2007 11:56:38 PM
On Wed, 26 Dec 2007 23:06:17 -0800 (PST), Archana
[quoted text, click to view]

You can do that. However, IDisposable is better, as it allows you to
use the "using" syntax to insure that Dispose is always called, even
if an exception occurs.

Using IDispose is also slightly better because it allows you to call
the Dispose method without having to know the type of the object,
Michael Nemtsev [MVP]
12/27/2007 8:58:38 AM
Hello archana,

see there http://msdn.microsoft.com/msdnmag/issues/07/07/CLRInsideOut/

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


a> Can anyone tell me exact use of idisposable interface.
a>

AddThis Social Bookmark Button