Why foreach works while removing items from ListView and doesn't work from ListBox?
问题 I've started learning C# and I'm a bit confused about the behavior that I discovered. I try to figure out, why in one case the code is working and in another not: foreach (ListViewItem l in listView1.SelectedItems) l.Remove(); foreach (object l in listBox1.SelectedItems) listBox1.Items.Remove(l); First one works fine and there is no error, but the second one throws exception with information that the collection was changed. Could anyone explain it to me? PS. In case of ListView I was