title: Read Big TXT File, Out of Memory Exception
body: <p>I want to read big TXT file size is 500 MB, 
  First I use </p>
  
  <pre><code>var file = new StreamReader(_filePath).ReadToEnd();  
  var lines = file.Split(new[] { '\n' });
  </code></pre>
  
  <p>but it throw out of memory Exception then I tried to read line by line but again after reading around 1.5 million lines it throw out of memory Exception</p>
  
  <pre><code>  using (StreamReader r = new StreamReader(_filePath))
           {            
               while ((line = r.ReadLine()) != null)            
                   _lines.Add(line);            
           }
  </code></pre>
  
  <p>or I used </p>
  
  <pre><code>  foreach (var l in File.ReadLines(_filePath))
              {
                  _lines.Add(l);
              }
  </code></pre>
  
  <p>but Again I received </p>
  
  <blockquote>
    <p>An exception of type 'System.OutOfMemoryException' occurred in
    mscorlib.dll but was not handled in user code</p>
  </blockquote>
  
  <p>My Machine is powerful machine with 8GB of ram so it shouldn't be my machine problem.</p>
  
  <p>p.s: I tried to open this file in NotePadd++ and I received 'the file is too big to be opened' exception.</p>