How to Convert IEnumerable<T> to ConcurrentBag<T> in C#?
ConcurrentBag
has a constructor that takes an IEnumerable
.
IEnumerable<T> myEnum = ...
ConcurrentBag<T> myBag = new ConcurrentBag<T>(myEnum);
You could use the proper constructor.
IEnumerable<Foo> foos = ...
ConcurrentBag<Foo> concurrentFoos = new ConcurrentBag<Foo>(foos);
ConcurrentBag<T>
has a constructor that takes an IEnumberable<T>
as input.
Several collections support this, so make sure to check the constructor overloads.