C# preventing Collection Was Modified exception

前端 未结 10 1765
梦毁少年i
梦毁少年i 2021-01-17 17:16

Does

 foreach(T value in new List(oldList) )

is dangerous (costly) when oldList contains 1 millions of object T ?

More g

10条回答
  •  野的像风
    2021-01-17 17:58

    I usually just create a list for all the objects to be removed or added.

    Within the foreach I just add the items to the appropriate collections and modify the original collection after the foreach have completed (loop through the removeItems and addItems collection)

提交回复
热议问题