I'm getting this error
System.InvalidOperationException: 'List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change.'
Because in my code, the Selected Items change during iteration
The code is simple
var items = testListBox.SelectedItems;
foreach (var item in items)
{
}
I want to freeze the items list in a variable, so that if it changes, the foreach
loop doesn't change and create this error
The problem is the line var items = testListBox.SelectedItems;
doesn't seem to work, because for some reason it still gives me this error
How can I clone the SelectedItems list to another variable so it doesn't crash on the foreach loop if the SelectedItems list changes
Thanks,