Diff between dispose() and close()

Posted by Vforvijay under VB.NET on 4/22/2011 | Points: 10 | Views : 2997 | Status : [Member] | Replies : 2
can any one tell me the difference between close() and dispose()...which one is best to close streamwriter...etc..




Responses

Posted by: SheoNarayan on: 4/22/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
For Stream objects first you should call the .Close() method and .Dispose() method.

Better to use using block while using Streams, eg.

using (StreamWriter writer = new StreamWriter......)

{
// your code goes here
}


Above will ensure that the stream writer is closed and disposed after the use

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Vforvijay, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 4/23/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
hi vforvijay

i think u use .Dispose() method . . it's best for StreamWriter

Best Regard's
Prabhakar

Vforvijay, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response