Can ICollection<T>.Count property getter be considered atomic (and, therefore, threadsafe)?
Thank you.
It completely depends on the collection; ICollection<T> is just an interface.
Every collection that I know of simply returns an Int32 field in its Count getter, so it usually is atomic.
However, there is never a guarantee that the count didn't change just after you fetched the property.
No, as you can only make that assumption for implementations, not an interface.
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