title: C# Read From Text File, New Line
body: <p>My code to write text to a file works perfectly...</p>
  
  <pre><code>        string path = @"./prefs.dat";
          string stringdir = textBox1.Text + Environment.NewLine + textBox2.Text + Environment.NewLine;
          System.IO.File.WriteAllText(path, stringdir);
  </code></pre>
  
  <p>Then to read from the file I use this code which again works perfectly...</p>
  
  <pre><code>        Process test = new Process();
          string FileName = "prefs.dat";
          StreamReader sr = new StreamReader(FileName);
          List&lt;string&gt; lines = new List&lt;string&gt;();
          lines.Add(sr.ReadLine());
          string s = lines[0];
          sr.Close();
          test.StartInfo.FileName = s;
          test.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
          test.StartInfo.CreateNoWindow = false;
          test.Start();
  </code></pre>
  
  <p>However when I want to read the 2nd line using the exact same code except changing...</p>
  
  <pre><code>       string s = lines[1]; 
  </code></pre>
  
  <p>Then it fails, I get a null result. When I look into further the error doesn't even see the 2nd line even though I clearly have two lines.</p>