ReadOnlyAttribute(Boolean) 建構函式

定義

初始化 ReadOnlyAttribute 類別的新執行個體。

public:
 ReadOnlyAttribute(bool isReadOnly);
public ReadOnlyAttribute (bool isReadOnly);
new System.ComponentModel.ReadOnlyAttribute : bool -> System.ComponentModel.ReadOnlyAttribute
Public Sub New (isReadOnly As Boolean)

參數

isReadOnly
Boolean

如果這個屬性 (Attribute) 繫結的屬性 (Property) 是唯讀的,則為 true;如果屬性 (property) 是可讀取/寫入的,則為 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

備註

標示ReadOnlyAttributetrue為 或沒有 Set 方法的成員無法變更。 沒有這個屬性或標示 ReadOnlyAttributefalse 的成員是可擦寫的,而且可以變更。 預設為 No

注意

當您將 屬性ReadOnlyAttributetrue標示為 時,這個屬性的值會設定為常數成員 Yes。 對於標示 ReadOnlyAttributefalse的屬性,此值為 No。 因此,當您要在程式碼中檢查此屬性的值時,必須將 屬性指定為 ReadOnlyAttribute.YesReadOnlyAttribute.No

適用於

另請參閱