I agree they serve completely different purpose, but people are mistaken about the purpose of the ConcurrentBag. If you think that ConcurrentBag is more suited than ConcurrentQueue to handle an unordered list of items, I invite you to benchmark your code and you’re in for a surprise.

The only scenario where ConcurrentBag performs better than ConcurrentQueue is when the same thread dequeues the items it has enqueued, and work-stealing is kept to a minimum (for instance, a threadpool).

Written by

Software developer passionate about .NET, performance, and debugging

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store