That does this text mean

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
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
 
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.
 
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.
 
Back
Top