Sorting Dictionary of key string and value List<string>

Viewed 53

I am iterating on the dictionary of string,List using keyvalue in foreach. While iterating. I add another item to it and after that, I try to sort the value of the list at that key.

Here is my code:

foreach (KeyValuePair<string, List<string>> itemList in myDic)
                {
                    if (anotherDict.ContainsKey(itemList.Key.ToLower()))
                    {
                        itemList.Value.Add(anotherDict[itemList.Key]);
                    }

                    var sortedList = itemList.Value.OrderBy(x => x).ToList();

                    Employees.Add(new Employee
                    {
                        Value = String.Join(",", sortedList),
                        Description = description,
                    });
                }

I also tried Sort() method but that is also not working.

itemList.Value.Sort();

if I am sorting a simple list it works but why its not working on the dictionary of the List

0 Answers
Related