Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Where to store collections in system.collections.concurrent?


Asked by Tobias Beil on Dec 01, 2021 FAQ



The classes in the System.Collections namespace do not store elements as specifically typed objects, but as objects of type Object. Whenever possible, you should use the generic collections in the System.Collections.Generic namespace or the System.Collections.Concurrent namespace instead of the legacy types in the System.Collections namespace.
Moreover,
The System.Collections.Concurrent namespace provides several thread-safe collection classes that should be used in place of the corresponding types in the System.Collections and System.Collections.Generic namespaces whenever multiple threads are accessing the collection concurrently.
Also, In c#, concurrent collections are useful to access a collection items from multiple threads and these are available from .NET Framework 4 with System.Collections.Concurrent namespace.
In fact,
For example, you could specify a ConcurrentQueue<T> object for first in, first out (FIFO) behavior, or a ConcurrentStack<T> object for last in, first out (LIFO) behavior. You can use any collection class that implements the IProducerConsumerCollection<T> interface.
One may also ask,
C# Collection Types 1 Non-Generic (System.Collections) 2 Generic (System.Collections.Generic) 3 Concurrent (System.Collections.Concurrent)