Last post Oct 27, 2013 06:58 AM by IranianCuriousBoy
Oct 26, 2013 09:33 AM|IranianCuriousBoy|LINK
I use the following code:
The stream2 is initialized. Is it necessary to close or dispose stream2 and then initialized it and then use it or doing this way simply works perfectly from performance and good practices perspective. I didn't understand difference of close and dispose
from documentation. Both of then release resourses. Can anyone give me explanation in these situations.
Oct 26, 2013 10:24 AM|a2h|LINK
In most .NET framework classes, there is no difference between Close() and
For example, these methods do the same thing in the System.IO.Stream hierarchy, and it doesn't matter which of the two methods you call. You should call one but not both.Infact when you call Close , this method calls Dispose, specifying true to release
But there are exceptions for ex System.Data.SqlClient.SqlConnection have different behavior for Close() and Dispose().
Here the major difference between calling the Close and Dispose methods
on database connections. Close leaves the connection in a closed state; but, it is reusable—all properties, etc. can be accessed and Open can
be called. On the other hand, after calling Dispose on a database connection—as with any object—, the connection object can no longer be accessed.
However, calling Dispose does not remove the connection from the connection pool.
You can find more details on this in below link
Oct 27, 2013 06:58 AM|IranianCuriousBoy|LINK
thank you. I read the link and it was very useful but a question remains and it is the behaviour of copy in stream. Is it necessary to close the old stream and then use copy with new stream?