I have few task which I can do in parallel. As list is not thread safe i am using concurrentbag. Once all the task are completed I want to convert the concurrentbag to list.
I have searched in MSDN but couldn't find any API which can convert concurrentbag to list in c#. How can I do it?
Note: i have to convert to list, It is necessary.
I have other option to apply lock on list but i wanted to use in build concurrentbag which is thread safe.
You could use ToList extension method.
var list = concurrentBag.ToList();
ConcurrentBag has the extension method of .ToList() - it implementsIEnumerable<T>
var someList = someConcurrentBag.ToList();
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