Answer: Dispose as name says,disposes all resources used by the System.IO.Streamreader object.When the streamreader object is disposed then it also closes the underlying stream.
Actually Dispose() is implemented in TextReader class,which is the base class for StreamReader.
For Example:
string file_contents;
using (StreamReader sr = new StreamReader("C:\\rpt.txt"))
{
file_contents = sr.ReadToEnd();
sr.Dispose();
}
Asked In: Many Interviews |
Alert Moderator