BlockingCollectionnumbers = new BlockingCollection (); numbers.Add(1); numbers.Add(2); numbers.Add(3); numbers.Clear();
ConcurrentDictionaryIn this example, we create a new ConcurrentDictionary instance called `dict` and add three key-value pairs to it. We then create a new BlockingCollection instance called `numbers` that uses a ConcurrentBag as its underlying collection. We add all values from the `dict` instance to the `numbers` collection using a foreach loop. Finally, we call the Clear method to remove all elements from the collection. The BlockingCollection Clear method is part of the System.Collections.Concurrent namespace in C#.dict = new ConcurrentDictionary (); BlockingCollection numbers = new BlockingCollection (new ConcurrentBag ()); dict.TryAdd("One", 1); dict.TryAdd("Two", 2); dict.TryAdd("Three", 3); foreach(var value in dict.Values) { numbers.Add(value); } numbers.Clear();