ICollection<T>.IsReadOnly 属性


获取一个值,用于指示 ICollection<T> 是否为只读。Gets a value indicating whether the ICollection<T> is read-only.

 property bool IsReadOnly { bool get(); };
public bool IsReadOnly { get; }
member this.IsReadOnly : bool
Public ReadOnly Property IsReadOnly As Boolean



如果 true 是只读的,则为 ICollection<T>;否则为 falsetrue if the ICollection<T> is read-only; otherwise, false.


只读集合不允许在创建集合后添加或删除元素。A collection that is read-only does not allow the addition or removal of elements after the collection is created. 请注意,在此上下文中为只读并不表示是否可以修改集合中的单个元素,因为 ICollection<T> 接口仅支持添加和删除操作。Note that read-only in this context does not indicate whether individual elements of the collection can be modified, since the ICollection<T> interface only supports addition and removal operations. 例如,强制转换或转换为 ICollection<T> 对象的数组的 IsReadOnly 属性返回 true,即使可以修改单个数组元素也是如此。For example, the IsReadOnly property of an array that is cast or converted to an ICollection<T> object returns true, even though individual array elements can be modified.