ReadOnlyAttribute(Boolean) 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 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 方法的成員無法更改。 沒有此屬性或以 ReadOnlyAttribute 為 false 標記的成員會被讀寫,且可以更改。 預設值為 No。
Note
當你將屬性標記為 ReadOnlyAttributetrue時,該屬性的值會被設定為常數成員 Yes。 對於標記為 ReadOnlyAttribute 的 false屬性,值為 No。 因此,當你想檢查程式碼中這個屬性的值時,必須指定為 ReadOnlyAttribute.Yes 或 ReadOnlyAttribute.No。