Click here to Skip to main content
15,889,724 members
Home / Discussions / C#
   

C#

 
GeneralRe: Diferences between null,close and dispose Pin
S. Senthil Kumar25-Apr-05 3:32
S. Senthil Kumar25-Apr-05 3:32 
GeneralRe: Diferences between null,close and dispose Pin
turbochimp25-Apr-05 5:54
turbochimp25-Apr-05 5:54 
GeneralRe: Diferences between null,close and dispose Pin
S. Senthil Kumar25-Apr-05 19:22
S. Senthil Kumar25-Apr-05 19:22 
GeneralRe: Diferences between null,close and dispose Pin
mav.northwind25-Apr-05 20:27
mav.northwind25-Apr-05 20:27 
GeneralRe: Diferences between null,close and dispose Pin
S. Senthil Kumar26-Apr-05 0:33
S. Senthil Kumar26-Apr-05 0:33 
GeneralRe: Diferences between null,close and dispose Pin
turbochimp26-Apr-05 5:10
turbochimp26-Apr-05 5:10 
GeneralRe: Diferences between null,close and dispose Pin
S. Senthil Kumar26-Apr-05 19:17
S. Senthil Kumar26-Apr-05 19:17 
GeneralRe: Diferences between null,close and dispose Pin
turbochimp27-Apr-05 5:19
turbochimp27-Apr-05 5:19 
While I would have to place myself in the "Richter" camp on this as well, I understand the point these articles are trying to make, and I don't know if I really disagree with their implementations, except possibly from an aesthetic point of view.

My thinking is:
1. Dispose() has a clear definition and purpose regardless of type. If the type has unmanaged resources, and it may be important to release those resources in a time-critical manner, then the type will likely benefit from a Dispose() method.
2. Close() has a somewhat less well-defined purpose that is affected by the type on which it is implemented. It has a high-level meaning that applies in most places (i.e. "To stop or obstruct some kind of operation or behavior") and means the same thing to most people, but the specifics of how to "Close" an instance of a type are potentially specific to the type itself, as are the rules about re-opening the instance, how closing affects state, etc.

There are clearly some cases where Close() and Dispose() might effectively mean the same thing, as the first article suggests, but there are obviously others (e.g. SqlConnection) where the intent of the developers was to make the methods behave differently. Both are okay in my book, but what can't get overlooked is that while Close() may or may not be implemented on a disposable type, the IDisposable interface ( thus Dispose() ) *must* be implemented, or unexpected results may ensue. In those cases where Close() and Dispose() are interchangeable, the word "Close" may be considered more "user friendly" or less confusing than "Dispose", and so a case can be made for implementing a Close() method that simply masks the Dispose() method.

In general though, I'd prefer a more expository API (one that had both methods marked public, if the developers really felt that strongly about it), but that's just me, and the decision really boils down to developer preference and the consuming client's perceived level of understanding.

Have a good one.

The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

GeneralRe: Diferences between null,close and dispose Pin
Tom Larsen25-Apr-05 9:31
Tom Larsen25-Apr-05 9:31 
GeneralRe: Diferences between null,close and dispose Pin
Enishi25-Apr-05 22:08
Enishi25-Apr-05 22:08 
GeneralCopy an excel document Pin
fatihsen25-Apr-05 1:34
fatihsen25-Apr-05 1:34 
GeneralRe: Copy an excel document Pin
turbochimp25-Apr-05 2:49
turbochimp25-Apr-05 2:49 
General[ActiveDirectory] Connect to group Pin
Jaymz66625-Apr-05 1:05
Jaymz66625-Apr-05 1:05 
Generalmixer - balance settings Pin
Mr.Dani25-Apr-05 0:24
Mr.Dani25-Apr-05 0:24 
QuestionHow to bind IList to a DataGridTableStyle? Pin
Member 59674924-Apr-05 23:15
Member 59674924-Apr-05 23:15 
AnswerRe: How to bind IList to a DataGridTableStyle? Pin
Anonymous25-Apr-05 1:08
Anonymous25-Apr-05 1:08 
Generalselecting row from datagrid Pin
anj198324-Apr-05 23:06
anj198324-Apr-05 23:06 
GeneralRe: selecting row from datagrid Pin
Polis Pilavas25-Apr-05 9:19
Polis Pilavas25-Apr-05 9:19 
Generalcontrol another pc in lan Pin
mtbjr24-Apr-05 22:31
mtbjr24-Apr-05 22:31 
GeneralRe: control another pc in lan Pin
.Anonymous25-Apr-05 14:32
suss.Anonymous25-Apr-05 14:32 
GeneralGet remote hardware profile Pin
Yeast2724-Apr-05 21:08
Yeast2724-Apr-05 21:08 
QuestionHow to handle event in PictureBox? Pin
TanutAPI24-Apr-05 19:22
TanutAPI24-Apr-05 19:22 
AnswerRe: How to handle event in PictureBox? Pin
Enishi25-Apr-05 1:43
Enishi25-Apr-05 1:43 
GeneralRe: How to handle event in PictureBox? Pin
TanutAPI25-Apr-05 17:15
TanutAPI25-Apr-05 17:15 
QuestionHow to make a loading screen? Pin
Anonymous24-Apr-05 14:43
Anonymous24-Apr-05 14:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.