Removing Items in a List While Iterating Through It with For Each Loop

前端 未结 7 2233
小鲜肉
小鲜肉 2021-01-17 09:56

I have a list named NeededList I need to check each item in this list to see if it exists in my database. If it does exist in the database I need to remove it

7条回答
  •  不要未来只要你来
    2021-01-17 10:13

    Go for safe and make a copy with ToList():

    For Each Needed In NeededList.ToList()
        Dim Ticker = Needed.Split("-")(0).Trim()
        ...
        If dr.HasRows Then
            NeededList.Remove(Needed)
        End If
    Next
    

提交回复
热议问题