Is this OK? (.Net 4.5)try{    StreamReader sr = = new StreamReader(ValidFilePathName);    line = file.ReadLine();    While (line != null)    {        line = file.ReadLine();    }    sr.Close();}catch{    // blah Do nothing}I feel like there is something wrong with my pattern here. My concern is that when there is a file exception, does the stream get closed properly? I was taught to use using to set the stream, but Code Analysis tool does not like it. Perhaps there is something else. It seems to read the file OK, but I remember needing to use File stream and stream reader in the past... Was there a good reason for combining the two?
Streamreader file.Readline properly closing the stream
c#;.net;stream
You always need to dispose of objects in the finally close to ensure that they are disposed correctly.StreamReader sr = null;try{    sr = = new StreamReader(ValidFilePathName);    line = file.ReadLine();    While (line != null)    {        line = file.ReadLine();    }}catch{    // blah Do nothing}finally{   if (sr != null)   {       sr.Close();   }       }