ConcurrenctBag(Of MyType) Vs List(Of MyType)

Posted by Ben on Stack Overflow See other posts from Stack Overflow or by Ben
Published on 2010-06-01T15:15:55Z Indexed on 2010/06/01 15:23 UTC
Read the original article Hit count: 187

Filed under:
|
|
|

What is the advantage of using a ConcurrentBag(Of MyType) against just using a List(Of MyType)? The MSDN page on the CB (http://msdn.microsoft.com/en-us/library/dd381779(v=VS.100).aspx) states that

ConcurrentBag(Of T) is a thread-safe bag implementation, optimized for scenarios where the same thread will be both producing and consuming data stored in the bag

So what is the advantage? I can understand the advantage of the other collection types in the Concurrency namespace, but this one puzzled me.

Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET