I've found the following code in a project I'm working on and I'm curious to know if it can be written more succinctly.
using (var stream = new FileStream(CustomSettingsFile.FullName, FileMode.Open, FileAccess.Read))
{
using (var reader = new StreamReader(stream))
{
var data = reader.ReadToEnd();
}
}
Firstly, what's the benefit of using FileStream? I understand that StreamReader can take a file path directly.
using (var reader = new StreamReader(CustomSettingsFile.FullName))
{
var data = reader.ReadToEnd();
}
Secondly, if I'm only using the reader once, can't I just anonymize it and omit the using?
var data = new StreamReader(CustomSettingsFile.FullName).ReadToEnd();