In the first declaration, you can still use the following:
strList[0] = "Not a fruit";
ReadOnlyCollection<T>
wraps any IList<T>
in a lightweight object. It passes all calls that wouldn't change the collection on to the wrapped object (get Count
, get Item[]
, GetEnumerator
), but throws an exception for all calls that would change the collection (Add
, Remove
, Clear
, set Item[]
).
Arrays are not resizable, but they are not readonly. The distinction is important to understand or you can introduce some serious security issues, for an example see Path.InvalidPathChars Field.