At first I used a StreamReader
to read text from a file:
StreamReader reader = new StreamReader(dialog.OpenFile());
txtEditor.Text = reader.ReadToEnd();
but found out about File.ReadAllText
which seems to simplify my code to 1 line. Are there are any differences between the two? When should I use one over the other?
txtEditor.Text = File.ReadAllText(dialog.FileName);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…