That does this text mean

T

Tony Johansson

Hello!

In a book that I'm reading it says.
"For some classes, the notion of a closse() method is more logical than
Dispose();for example
when dealing with files or database connections. In these cases it is common
to implement the IDisposable interface and then implement a separate Close()
method that simply calls Dispose(). This approach provides clarity in the
use of your classes but also supports the using statement provided by C#:"!

Can somebidy explain what this text is trying to say.

//Tony
 
W

Willem van Rumpt

Hello!

In a book that I'm reading it says.
"For some classes, the notion of a closse() method is more logical than
Dispose();for example
when dealing with files or database connections. In these cases it is common
to implement the IDisposable interface and then implement a separate Close()
method that simply calls Dispose(). This approach provides clarity in the
use of your classes but also supports the using statement provided by C#:"!

Can somebidy explain what this text is trying to say.

The text is explaining that in some situations, it feels and sounds more
natural for a programmer to call a "Close()" method than to invoke a
"Dispose()" method.

For instance, natural operations associated with a file or a database
connection are opening and closing it. You open one, and when you're
done, you close it. That's why in those case an additional Close()
method was added: To follow "natural" semantics associated with the
resource.

Technically, this didn't have to be done, since Dispose() could've been
called, but to make it look more natural, they added a Close() method
which does the same thing for you.
 
T

Tony Johansson

Good explained!!

//Tony

Willem van Rumpt said:
The text is explaining that in some situations, it feels and sounds more
natural for a programmer to call a "Close()" method than to invoke a
"Dispose()" method.

For instance, natural operations associated with a file or a database
connection are opening and closing it. You open one, and when you're done,
you close it. That's why in those case an additional Close() method was
added: To follow "natural" semantics associated with the resource.

Technically, this didn't have to be done, since Dispose() could've been
called, but to make it look more natural, they added a Close() method
which does the same thing for you.
 

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