For Lists I could use the Union method:
var finalCollection = new List<MyType>();
var list1= new List<MyType>();
var list2 = new List<MyType>();
finalCollection = list1.Union(list2).ToList();
But when I try to do the same with ConcurrentBags,
var finalCollection = new ConcurrentBag<MyType>();
var bag1= new ConcurrentBag<MyType>();
var bag2= new ConcurrentBag<MyType>();
finalCollection = bag1.Union(bag2);
I get:
Cannot implicitly convert type "System.Collections.Generic.IEnumerable< MyType>" to "System.Collections.Concurrent.ConcurrentBag"
Perhaps the problem is you are trying to Union the elements into a new
ConcurrentBagWhat you actually get after the union is an
IEnumerableofMyTypeTo get back a
ConcurrentBagtry doing it like so: