List Of Dictionary to List of List<string> in LINQ

HI I have this example data which is in List<Dictionary<string,string>>

var menu = new List<Dictionary<string,string>> { new Dictionary<string, string> { { "Meal", "Pasta" }, { "Meal", "Pizza" } } , new Dictionary<string, string> { { "Entree", "Calamari Salad" } } },

I need to convert the above list to something like this

var menu = new List<List<string>> { new List<string> { "Meal:Pasta", "Meal:Pizza" }, new List<string> { "Entree:Calamari Salad" } };

how can I do this with LINQ query?

>Solution :

You can try like below.

var result = menu.Select(x => x.Select(y => $"{y.Key}:{y.Value}"));

Leave a Reply