VB.NET Filtering ListItems Problem

后端 未结 5 690
北荒
北荒 2021-01-25 11:15

I am trying to filter a ListBox based on the presence of a string. Basically, if there is a ListItem that doesn\'t contain the string then I want to remove all ListItems that do

5条回答
  •  北荒
    北荒 (楼主)
    2021-01-25 11:33

    Try reversing your loop, i.e. start from the end of the list. That way, deleting items won't shift the index of the remaining items you still have to check (which is the cause of your out of range exception).

    The first way causes a problem because you're modifying the list while iterating over it. And that is, as you said, a big no-no.

提交回复
热议问题