So far I've found 2 ways to delete selected items from a listbox (winform):
1.
ListBox.SelectedObjectCollection tempCollection = new ListBox.SelectedObjectCollection(myListBox);
for (int i = tempCollection.Count - 1; i >= 0; i--)
{
myListBox.Items.Remove(tempCollection[i]);
}
2.
while (myListBox.SelectedItems.Count > 0)
{
myListBox.Items.Remove(myListBox.SelectedItem);
// or
//myListBox.Items.Remove(myListBox.SelectedItems[0]);
}
The 2nd way is easy to understand, but the 1st one is strange for me. They're both work for me, I just want to know the difference?