How to add items to a collection while consuming it?

后端 未结 11 557
离开以前
离开以前 2021-01-15 12:44

The example below throws an InvalidOperationException, \"Collection was modified; enumeration operation may not execute.\" when executing the code.

var urls         


        
11条回答
  •  情话喂你
    2021-01-15 12:52

    Consider using a Queue with while loop (while q.Count > 0, url = q.Dequeue()) instead of iteration.

提交回复
热议问题