I am confused about implementing interfaces.
According to MSDN, ICollection<T> has the IsReadOnly property
th -
According to MSDN Collection<T> implements ICollection<T>
-So -
I thought Collection<T> would have the IsReadOnly property.
-However -
Collection<string> testCollection = new Collection<string>(); Console.WriteLine(testCollection.IsReadOnly);
The above code gives a 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?)
-Although -
Collection<string> testInterface = new Collection<string>(); Console.WriteLine(((ICollection<string>)testInterface).IsReadOnly);
The above code works.
-Question -
I thought classes that implement interfaces should implement each property, so why testCollection n't testCollection have IsReadOnly property if you don't use it as ICollection<string> ?
source share