ReadOnlyAttribute(Boolean) 构造函数  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 ReadOnlyAttribute 类的新实例。
public:
 ReadOnlyAttribute(bool isReadOnly);public ReadOnlyAttribute (bool isReadOnly);new System.ComponentModel.ReadOnlyAttribute : bool -> System.ComponentModel.ReadOnlyAttributePublic Sub New (isReadOnly As Boolean)参数
- isReadOnly
- Boolean
如果该特性所绑定到的属性为只读属性,则为 true;如果该属性为读/写属性,则为 false。
示例
下面的代码示例将属性标记为只读。 此代码创建一个新的 ReadOnlyAttribute,将其值设置为 ReadOnlyAttribute.Yes,并将其绑定到 属性。
public:
   [ReadOnly(true)]
   property int MyProperty 
   {
      int get()
      {
         // Insert code here.
         return 0;
      }
      void set( int value )
      {
         // Insert code here.
      }
   }
[ReadOnly(true)]
public int MyProperty {
   get {
      // Insert code here.
      return 0;
   }
   set {
      // Insert code here.
   }
}
<ReadOnlyAttribute(True)> _
Public Property MyProperty() As Integer
    Get
        ' Insert code here.
        Return 0
    End Get
    Set
        ' Insert code here.
    End Set
End Property
注解
不能更改标记为 ReadOnlyAttribute 设置为 true 的成员,或者没有 Set 方法的成员。 不具有此属性或标记为 ReadOnlyAttribute 设置为 false 的成员是可读/写的,可以更改它们。 默认为 No。
注意
将 属性ReadOnlyAttributetrue标记为 时,此属性的值设置为常量成员 Yes。 对于标记为 的 ReadOnlyAttributefalse属性,设置为 ,值为 No。 因此,如果要在代码中检查此属性的值,则必须将特性指定为 ReadOnlyAttribute.Yes 或 ReadOnlyAttribute.No。