I have this code, I am worried that it is "unsafe", I used Dispose () before the end of use, for me it is a little illogical, but everything works fine. So is it safe?
using (FileStream stream = new FileStream(SfilePath, FileMode.Open)) { try { XmlSerializer deserializer = new XmlSerializer(typeof(HighscoresViewModel)); HVM = deserializer.Deserialize(stream) as HighscoresViewModel; } catch (InvalidOperationException) { stream.Dispose(); (new FileInfo(SfilePath)).Delete(); HVM = new HighscoresViewModel(); } }
c # using-statement
Imad nabil alnatsheh
source share