Namespace:
System.Collections.Concurrent
Assembly:
System.Threading (in System.Threading.dll)
Syntax
Visual Basic (Declaration) |
---|
<SerializableAttribute> _ <ComVisibleAttribute(False)> _ <HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization := True, _ ExternalThreading := True)> _ Public Class ConcurrentBag(Of T) _ Implements IProducerConsumerCollection(Of T), IEnumerable(Of T), _ ICollection, IEnumerable |
C# |
---|
[SerializableAttribute] [ComVisibleAttribute(false)] [HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)] public class ConcurrentBag<T> : IProducerConsumerCollection<T>, IEnumerable<T>, ICollection, IEnumerable |
Type Parameters
- T
- Specifies the type of elements in the bag.
Remarks
Bags are useful for storing objects when ordering doesn't matter, and unlike sets, bags support duplicates. 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.
ConcurrentBag<(Of <(T>)>) accepts null reference (Nothing in Visual Basic) as a valid value for reference types.
All public and protected members of ConcurrentBag<(Of <(T>)>) are thread-safe and may be used concurrently from multiple threads.
Inheritance Hierarchy
System.Collections.Concurrent..::.ConcurrentBag<(Of <(T>)>)