Code Anlysis Rule CA2000 / CA2202

前端 未结 3 594
日久生厌
日久生厌 2020-12-18 05:39

I am trying to ensure my coding follows correct disposal of objects so I am enforcing these rules as errors. But I am having trouble with this section of code



        
3条回答
  •  萌比男神i
    2020-12-18 05:54

    If you dispose the StreamReader, you are also disposing the underlying stream.

    If you comment out objStream.Dispose() then you run into the chance of something throwing an exception before you even get to the nested try block - which will result in your stream not getting disposed.

    There's a nice explanation here: Does disposing streamreader close the stream?

提交回复
热议问题