How to remove all Items from ConcurrentBag?

前端 未结 6 1220
猫巷女王i
猫巷女王i 2021-01-31 13:30

How to clear the ConcurrentBag? it don\'t have any method like Clear or RemoveAll...

6条回答
  •  天命终不由人
    2021-01-31 13:34

    In the spirit of workarounds.. ConcurrentDictionary has an atomic Clear, but also allows you to quickly check if a key exists. 'Quickly' is a relative term of course, but depending on your usage it might be faster than enumerating a large stack.

提交回复
热议问题