Home > DeveloperSection > Forums > How to populate a list inside a dictionary?
ben reitman
ben reitman

Total Post:96

Posted on    December-16-2013 12:40 AM

 C# C# 

 1 Reply(s)
 1612  View(s)
Rate this:

I have a dictionary that needs to be populate with a list. The code below does not work. How would I fix it?


public Dictionary<int, List<string>> Languages { get; set; }


var ClientsData = new List<MapModel.ClientInfo> { }

   ClientsData.Add(new MapModel.ClientInfo { Id = IDCounterDoctors, Languages = new Dictionary<int, List<string>>()});

   ClientsData[0].Languages.Add(2376, ["english", "french"]); // issue is here

Pravesh Singh

Total Post:412

Posted on    December-16-2013 12:55 AM

Hi Ben,

Your initialization of list is wrong. Also make sure your languages property is initialized

ClientsData[0].Languages = new Dictionary<int,List<string>>();

ClientsData[0].Languages.Add(2376,new List<string>(){ "english", "french"});

Don't want to miss updates? Please click the below button!

Follow MindStick