I have a stream reader inside a using block of code in C#. Do I need to call reader. Close as part of this to close off the process and allow GC to clean up any memory or does it happen on its own? Here is the code that I am using.
using (StreamReader reader = new StreamReader(responseStream))
{
string fileContents = reader.ReadToEnd();
reader.Close();
}
1 Answer
No, there is no need to explicitly call reader.Close if the reading process is inside a using block. By using a using statement (that sounds awkward out loud) everything will be closed and disposed when the code exits the block. It is all handled as part of the i disposable interface that the stream reader implements.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String