Array.IsReadOnly 属性

定义

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

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

属性值

对于所有数组,此属性始终为 falseThis property is always false for all arrays.

实现

注解

Array 实现 IsReadOnly 属性,因为 System.Collections.IList 接口需要此属性。Array implements the IsReadOnly property because it is required by the System.Collections.IList interface. 如果数组为只读,则在创建数组后,不允许添加、移除或修改元素。An array that is read-only does not allow the addition, removal, or modification of elements after the array is created.

如果需要只读集合,请使用实现 System.Collections.IList 接口的 System.Collections 类。If you require a read-only collection, use a System.Collections class that implements the System.Collections.IList interface.

如果将数组强制转换或转换为 IList 接口对象,则 IList.IsReadOnly 属性将返回 falseIf you cast or convert an array to an IList interface object, the IList.IsReadOnly property returns false. 但是,如果将数组强制转换或转换为 IList<T> 接口,则 IsReadOnly 属性将返回 trueHowever, if you cast or convert an array to a IList<T> interface, the IsReadOnly property returns true.

检索此属性的值的运算复杂度为 O(1)。Retrieving the value of this property is an O(1) operation.

适用于

另请参阅