My linq query returns a collection of IEnumerable<object>
.
How can I convert this into a strongly typed object of collection ConcurrentBag<object>
?
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.
Here is the extension method:
public static ConcurrentBag<T> ToConcurrentBag<T>(this IEnumerable<T> source) => new ConcurrentBag<T>(source);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With