How / Why is SyncRoot hidden in the <T> queue?
Confused and missing something simple.
I have
var q = new Queue<object>(); lock (q.SyncRoot) { ... } I get
Queue<T> does not provide a defintion for SyncRoot blah blah... but Queue<T> implements ICollection , which defines SyncRoot as a public property.
So, first of all, why is it hidden. Secondly, how can you hide the property of the interface that you are implementing?
You can hide the property to implement it explicitly :
object MyQueue.SyncRoot { get; set; } It is hidden because it is out of date :
We found that the SyncRoot sync API is not enough for most scenarios. APIs allow secure secure access to a single member of the collection. The problem is that there are many scenarios in which you need to block several operations (for example, delete one element and add another). In other words, it is usually code that uses a collection that wants to select (and can actually implement) the correct synchronization policy, and not the collection itself. We found that SyncRoot is actually used very rarely, and when it is used, it does not really add much value. In cases where it is not used, this is just an annoyance for ICollection developers.
This is an example of an " explicit implementation of an interface .
When you implement the interface explicitly, you can only access this method using a link of this type of this instance. In other words, if you click Queue on ICollection , you will see a member of the synchronization root.