From MSDN:
IList is a descendant of the
ICollection interface and is the base
interface of all non-generic lists.
IList implementations fall into three
categories: read-only, fixed-size, and
variable-size. A read-only IList
cannot be modified. A fixed-size IList
does not allow the addition or removal
of elements, but it allows the
modification of existing elements. A
variable-size IList allows the
addition, removal, and modification of
elements.
The ICollection<T> interface does not have an indexer, so a fixed-size ICollection<T> is automatically readonly - there is no way to modify an existing item.
Possibly ICollection<T>.IsFixedSize would have been a better property name than ICollection<T>.IsReadOnly, but both imply the same thing - impossible to add or remove elements, i.e. the same as IList.IsFixedSize.
An array is a fixed-size list, but is not readonly as elements can be modified.
As an ICollection<T>, it is readonly, since an ICollection<T> has no way to modify elements.
This may appear confusing, but it is consistent and logical.
What is slightly inconsistent is that the generic IList<T> interface has an IsReadOnly property inherited from ICollection<T> whose semantics are therefore different from the non-generic IList.IsReadOnly. I imagine the designers were aware of this inconsistency but were unable to go back and change the semantics of the non-generic IList for backwards compatibility reasons.
To summarize, an IList can be:
Variable-size.
IList.IsFixedSize = false
IList.IsReadOnly = false
ICollection<T>.IsReadOnly = false
Fixed-size (but elements can be modified, e.g. an Array)
IList.IsFixedSize = true
IList.IsReadOnly = false
ICollection<T>.IsReadOnly = true
Read-only (elements can not be modified)
IList.IsFixedSize = true
IList.IsReadOnly = true
ICollection<T>.IsReadOnly = true
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…