I have a list of dictionary:
List<Dictionary<string, string>> items = new List<Dictionary<string, string>>();
foreach (var group in groupedItems)
{
foreach (var item in group)
{
Dictionary<string, string> newItem = new Dictionary<string, string>();
newItem.Add("name", item.Name);
newItem.Add("value", item.Value);
}
}
items.Add(newItem);
Basically when I loop through the grouped items, I create a Dictionary where the key is the item.Name and value is item.Value. In a grouped case, this will result in duplicate dictionaries to the list.
How can I avoid adding duplicate Dictionary to this List?
I have a foreach loop and I want to add some items once.
groupedItemsandnewItemis used outside of its scope