-3

Is there any Using.System command or anything else, to close the automatically StreamReader.

I've been closing the StreamReader like this e.g.:

sr.Close();
Kevin Garnick
  • 94
  • 1
  • 9

1 Answers1

3

If you implement a using statement the streamreader will be disposed automatically.

using (StreamReader r = new StreamReader("file.txt"))
{
  allFileText = r.ReadToEnd();
}
Kyle
  • 1,013
  • 8
  • 16
  • 2
    Since OP is so new, it might be worth mentioning that "dispose" can be presumed to include `Close()`. I recently spotted some old production code where a relatively experienced developer, years ago, assumed otherwise. – 15ee8f99-57ff-4f92-890c-b56153 May 25 '18 at 17:39