What is the use of Dispose() method of streamreader class?

 Posted by vishalneeraj-24503 on 1/28/2014 | Category: C# Interview questions | Views: 1565 | Points: 40
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 

Comments or Responses

Login to post response