Use of idisposable interface.

  • Thread starter Thread starter Archana
  • Start date Start date
A

Archana

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.

thanks in advance.
 
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.

thanks in advance.

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,
although in practice this probably rarely occurs.
 
Back
Top