There is one drawback to the option
using (StreamReader sr = new StreamReader(File.Open("history.txt", FileMode.Open))) { while (!sr.EndOfStream) listHistory.Items.Add(sr.ReadLine()); }
We have to call the file many times. And this is quite a long process.
It is more logical to read the entire sr.ReadToEnd () file;
And then split the file into parts in the code itself.
Like that
string[] strings; using (StreamReader sr = new StreamReader(@"path.txt")) { strings = sr.ReadToEnd().Split(new char[] { '\n' }); }
If I'm wrong, I would ask for a fix. The code above is a compressed version of this code.
string[] strings; using (StreamReader sr = new StreamReader(@"path.txt")) { string s = sr.ReadToEnd(); char[] divizorz = new char[] { '\n' }; strings = s.Split(divizorz); }
Just in my opinion the top is better, because the code is not cluttered with unnecessary names
Here \ n it means a newline character