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

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.
        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 方法的成員無法更改。 沒有此屬性或以 ReadOnlyAttributefalse 標記的成員會被讀寫,且可以更改。 預設值為 No

Note

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

適用於

另請參閱