I am Iterating through a Dictionary and I want to trying to remove certain un required keys from the Dictionary .
My code is as follows
foreach (KeyValuePair<string, string> stackOfItems in ItemStack)
            {
                string Name = stackOfItems .Key;
                string Price= stackOfItems .Value;
                if (listOfSelectedOldItems.Contains(Name))
                {
                    ItemStack.Remove(Name);
                }
            }
All I am trying to do is removing a Dictionary entry (key and value) if a certain Key is in a List . The full error :- System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute.' in dictionary
Can anyone please help me with this
 
    