title: Reading in a CSV file
body: <p>I have written a small program to read data from a <code>csv</code> file:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.IO;
  
  namespace test
  {
      class Program
      {
          static void Main( string[] args )
          {    
              var reader = new StreamReader( File.OpenRead( @"C:\Users\Desktop\Results.csv" ) );
  
              List&lt;string&gt; listA = new List&lt;string&gt;();
              List&lt;string&gt; listB = new List&lt;string&gt;();
  
              while ( !reader.EndOfStream )
              {
                  var line   = reader.ReadLine();
                  var values = line.Split( ',' );
  
                  listA.Add( values[0] );
                  listB.Add( values[1] );
              }
  
              // Print column one.
              Console.WriteLine( "Column 1:" );
              foreach ( var element in listA )
                  Console.WriteLine( element );
  
              // Print column two.
              Console.WriteLine( "Column 2:" );
              foreach ( var element in listB )
                  Console.WriteLine( element );
  
              Console.ReadKey();
          }
      }
  }
  </code></pre>
  
  <p>I get the following error message on line <code>listB.Add( values[1] );</code></p>
  
  <pre><code>Index was outside the bounds of the array.
  </code></pre>
  
  <p>When I comment out everything to do with <code>listB</code>, it works and shows me the 1st column...</p>
  
  <p>Could someone please help me understand what I am doing wrong?</p>
  
  <p>Thank you,</p>