Reputation: 6679
In the .Net Framework, List<T>
implements the ICollection<T>
interface. However when looking at the List class in Visual Studio, I see no IsReadOnly
property, which is supposedly in the ICollection<T>
interface.
How is it possible for a class to implement an interface... but not really implement it?
Upvotes: 2
Views: 101
Reputation: 700382
It's made using an explicit interface implementation. You can only see the implementation when you use the list as that specific interface:
List<int> x = new List<int>();
bool b1 = x.IsReadOnly; // not accessible
ICollection<T> y = x;
bool b2 = y.IsReadOnly; // accessible
Upvotes: 1
Reputation: 116411
IsReadOnly
is listed under the Explicit Interface Implementations section of the documentation.
Upvotes: 2
Reputation: 1500903
It uses explicit interface implementation. For example:
public interface IFoo
{
void Bar();
}
public Foo : IFoo
{
// Note the lack of public here
void IFoo.Bar() {}
}
Upvotes: 5