c# - Create new Dictionary<string, IEnumerable type using IDictionary -
Hello I have a list of users, each user belongs to an area.
What I want to do with this list, make a dictionary from them, where the name of the field is the key and the value for the key is in the list users in the user's text value and the value set on the user id Field with
I have been able to get it using the following code:
var StaffByArea = new dictionary & lt; String, IEnumerable & lt; SelectListItem & gt; & Gt; (); Forrest (diverse area in the area)) {var personList = new list & lt; SelectListItem & gt; (); Forward (Employee in Work Viewer (where C = & gt; C. AreaID == field.id)) {person list. Add (new selectionTitim {value = person.airid.ToString (), text = person.username}); } StaffByArea.Add (area name, person list); } So for every possible area, I am searching for staff and adding them to a selection list. Once all the people have been added to this area, then I add that selection list to the dictionary as the key in the name of the field.
I'm thinking that it can be easy to do this with ToDictionary ()
Does anyone know how to do this?
I just found:
StaffByArea = Users.ToDictionary (x = & gt; x.Area.Name, ...);
Try this:
var StaffByArea = Areas.ToDictionary (a = & Gt; a.Name, a = & gt; Staff where (C => c.AreaId == Area.id). Select (c => New Selection Item Item {value = c.AreaId. ToString (), text = c.Username}));
Comments
Post a Comment