1

The current implementation looks like this:

public class BlockingCollection<T> : IEnumerable<T>, ICollection, IEnumerable, IDisposable

Does anyone have an idea why it does not implement ICollection<T> as well? It's kind of anoying...

AcidJunkie
  • 1,878
  • 18
  • 21
  • According to [the documentation](https://msdn.microsoft.com/en-us/library/dd267312.aspx) it also implements `IReadOnlyCollection` (.net 4.5+). – Uwe Keim Dec 11 '15 at 15:41
  • 2
    The class isn't sealed, so if you really need it to implement that you could inherit and proxy the implementation manually. – Bradley Uffner Dec 11 '15 at 15:42
  • @UweKeim Sure, but i want to add some items to the collection too... – AcidJunkie Dec 11 '15 at 15:50
  • 2
    Do keep in mind that `ICollection` is very different from `ICollection`. The Contains() method is the deal-breaker imo, essential to ICollection<> but can't implement it in an efficient thread-safe way. – Hans Passant Dec 11 '15 at 16:33
  • Check out a very close question "Why doesn't ConcurrentBag implement ICollection?" https://stackoverflow.com/q/5611781/2680660 – Efreeto Oct 16 '20 at 19:00

1 Answers1

1

For one it does not implement ICollection.Contains Method (T)
As commented by Hans Contains() method cannot be implemented in an efficient thread-safe way.

paparazzo
  • 44,497
  • 23
  • 105
  • 176