Do I need to explicitly close the StreamReader in C# when using it to load a file into a string variable?

后端 未结 6 653
予麋鹿
予麋鹿 2020-12-05 12:53

Example:

variable = new StreamReader( file ).ReadToEnd();

Is that acceptable?

6条回答
  •  伪装坚强ぢ
    2020-12-05 13:38

    You're better off using the using keyword; then you don't need to explicitly close anything.

提交回复
热议问题