title: Read carriage return at end of file
body: <p>I am writing a validation class to ensure valid files are being sent to 3rd party software. These files require a carriage return at the end but when I read them in to ensure that there is a carriage return at the end of the file the libraries I have used ignore the last line. If I put a space in this line it will read it but if I don't it gets ignored.</p>
  
  <p>I've tried <code>System.IO.File</code>, <code>FileStream.ReadLines</code>, <code>StreamReader</code>, and <code>StringReader</code> using all the methods these classes have <code>ReadAllLines()</code>, <code>ReadAllText()</code>, <code>ReadLines()</code>, etc. </p>
  
  <p>Anyone know of a way around this. I haven't managed to find anything so far.</p>
  
  <p>Currently, this is the line of code I have </p>
  
  <pre><code>private void readfile()
  {
      string[] lines = System.IO.File.ReadAllLines(filePath + file); 
  
       bool error  = ErrorValidatingLastLineOfFile(lines, lines.count());
  }
  
  private bool ErrorValidatingLastLineOfFile(string[] lines, int lastLine)
  {
      if (lines[lastLine - 1] != "")
          return true;
  
      return false;
  }
  </code></pre>
  
  <p>Example of file: </p>
  
  <pre><code> 1. [Section1]
   2. Error = 
   3. 
   4. [Section2]
   5. Error = 
   6.
   7. [Data]
   8. foo,bar,
   9.
  </code></pre>
  
  <p>numbers are lines on the file not acutally in file. </p>