Q:

Last two elements in dictionary are skipped while inserting key/value pairs from a file

I'm trying to add all the key value pairs from a .txt document into a dictionary and the first two elements of the dictionary are getting skipped for some reason. I have a simple text file that reads

1:One
  2:Two
  3:Three
  4:Four
  5:Five
  6:Six
  7:Seven
  8:Eight
  9:Nine
  10:Ten

I have a dictionary declared as:
Dictionary<String,String> Test = new Dictionary<String,String>();

and a List for testing purposes as:
List<String> questionsList = new List<String>();
List<String> possibleAnswers = new List<String>();

Code that reads file:
using (StreamReader sr = new StreamReader(FilePath))
{
   String keyValue;

   char[] delimiterChars = {':'};

   while (!sr.EndOfStream)
   {
       keyValue = sr.ReadLine();
       String[] parts = keyValue.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
       Test.Add(parts[0], parts[1]); 
       questionsList.Add(parts[0]);
       possibleAnswers.Add(parts[1]);
  }
}

When I debug the program is shows that the Test dictionary count is 8 when it should be 10 and is populated as follows:

[0]    {[3, Three]}
  [1]     {[4, Four]}
  [2]     {[5, Five]}
  [3]     {[6, Six]}
  [4]     {[7, Seven]
  [5]     {[8, Eight]}
  [6]     {[9, Nine]}
  [7]     {[10, Ten]}

But the questionsList and possibleAnswer List holds all the values they're supposed to from reading the file. Can someone please give me some insight on this, i'm sure i'm just missing something stupid. Thanks in advanced.

A:

Your code works fine for me. I just wanted to point but that your code for the Dictionary can be greatly simplified like this:
var dictionary = File.ReadAllLines(file)
                     .ToDictionary(x => x.Split(':')[0], 
                                   x => x.Split(':')[1]);

