Use of idisposable interface.

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.
 
J

Jack Jackson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top