loop over items in dictionary and printing to console

  • Thread starter Thread starter thurlbred
  • Start date Start date
T

thurlbred

Guest
Please add a new value, the key of which is your name, and the value of which is your age. Do this using the Add method.

Next, add another value to the dictionary using the index notation. This time, use a different name and a different age.

Lastly, read the first item you added to the dictionary, and write it to the console using Console.WriteLine`.


THIS IS MY CODE

using System;
using System.Collections.Generic;

public class Program
{
public static void Main()
{
Dictionary<string, int> people = new Dictionary<string, int>();

// Your code here.
people.Add("Amber ", 31);
people["Chris "] = 40;

foreach (KeyValuePair<string, int> pair in people)
{

Console.WriteLine(31);
}
}
}


THIS IS THE ERROR I GET

You must call Console.WriteLine passing in the value of the first item you added to the dictionary.

Continue reading...
 
Back
Top