title: Reading only specific columns from a CSV file out of many
body: <p>I have a CSV file which looks like this basically:</p>
  
  <pre><code>TransactionID         ProfileID       Date           // more columns here...
  somevalue             123123123      somedate
  somevalue             123123123      somedate              
  somevalue             123123123      somedate
  somevalue             123123123      somedate
  somevalue             123123123      somedate
  </code></pre>
  
  <p>I would like to extract only specific columns which are ProfileID and Date out of all these columns from the CSV file, either by mapping it to an existing class like this:</p>
  
  <pre><code>public class MyMappedCSVFile
  {
    public string ProfileID { get; set; } 
    public string Date { get; set; }
  }
  </code></pre>
  
  <p>Or by storing it in a Dictionary collection?</p>
  
  <p>I have tried something like this:</p>
  
  <pre><code>   public static List&lt;string&gt; ReadInCSV(string absolutePath)
          {
              List&lt;string&gt; result = new List&lt;string&gt;();
              string value;
              using (TextReader fileReader = File.OpenText(absolutePath))
              {
                  var csv = new CsvReader(fileReader);
                  csv.Configuration.HasHeaderRecord = false;
                  while (csv.Read())
                  {
                      for (int i = 0; csv.TryGetField&lt;string&gt;(i, out value); i++)
                      {
                          result.Add(value);
                      }
                  }
              }
              return result;
          }
  </code></pre>
  
  <p>But this takes out everything out of the CSV file, literally everything in a single List, and it's not what I want...</p>
  
  <p>Can someone help me out with this ?</p>