I want to copy a BlockingCollection
and edit the copy.
(dataModelCollection
is the copy of DataModelListRaw
)
When I do this:
BlockingCollection<DataModel> dataModelCollection = DataModelListRaw;
while (dataModelCollection.TryTake(out _)) { }
I clear also the origin, because of the reference.
If I fill the new BlockingCollection
item for item, like this:
BlockingCollection<DataModel> dataModelCollection = new();
foreach(var datamodel in DataModelListRaw)
{
dataModelCollection.Add(datamodel);
}
while (dataModelCollection.TryTake(out _)) { }
it works.
But is there a shorter and more elegant way to do this copy? Maybe a method in BlockingCollection
?