I'm confused about the implementation of interfaces.
According to MSDN ICollection<T>
has the property IsReadOnly
-And-
According to MSDN Collection<T>
implements ICollection<T>
-So-
I thought that Collection<T>
would have the property IsReadOnly
.
-However-
Collection<string> testCollection = new Collection<string>();
Console.WriteLine(testCollection.IsReadOnly);
The above code gives the compiler error:
'System.Collections.ObjectModel.Collection<string>' does not contain a definition for 'IsReadOnly' and no extension method 'IsReadOnly' accepting a first argument of type
'System.Collections.ObjectModel.Collection<string>' could be found (are you missing a using directive or an assembly reference?)
-While-
Collection<string> testInterface = new Collection<string>();
Console.WriteLine(((ICollection<string>)testInterface).IsReadOnly);
The above code works.
-Question-
I thought classes implementing interfaces had to implement every property, so why doesn't testCollection
have the IsReadOnly
property unless you cast it as ICollection<string>
?