title: C#: add data to dictionary from datafile
body: <p>I'm trying to make import a data file and store all the values in the file in a dictionary.</p>
  
  <p>The data looks like this:</p>
  
  <pre><code>1,101,2.5
  4,103,3.0
  1,103,3.0
  1,104,3.5
  </code></pre>
  
  <p>I want to store the first(=key) and the last value(=value) in a dictionary. I have loaded the datafile and made a dictionary called: userPreferences.</p>
  
  <pre><code>System.IO.StreamReader file = new System.IO.StreamReader(@"datafile.data");
  Dictionary&lt;int, int&gt; userPreferences = new Dictionary&lt;int, int&gt;();
  </code></pre>
  
  <p>Now I want to make a loop that gets all the rows in the datafile and adds them to the dictionary.</p>
  
  <pre><code>foreach(?)
  {
     string[] columns = line.Split(','); 
     userPreferences.Add(int.Parse(columns[0]), int.Parse(columns[1]));
  } 
  </code></pre>
  
  <p>I dont know where my foreach needs to loop through. I thought about something like this: <code>foreach(DataRow row in file.Tables[0].Rows)</code></p>
  
  <p>My question is how can I get all the data from the file in a dictionary?</p>