|
|
Title | Use the DefaultValue attribute in VB .NET |
Description | This example shows how to use the DefaultValue attribute in VB .NET. |
Keywords | DefaultValue, DefaultValueAttribute, attribute, VB.NET, property |
Categories | VB.NET |
|
|
The DefaultValue attribute gives a property's default value. If you right-click on the property in the Properties window and select Reset, the property is reset to this value.
Usually the DefaultValue is the same as the property's initial value. This example uses the same constant for the FirstName property's initial and default values.
|
|
Private Const m_DefaultFirstName As String = "<unknown " & _
"first name>"
Private m_FirstName As String = m_DefaultFirstName
<DefaultValue(m_DefaultFirstName)> _
Public Property FirstName() As String
Get
Return m_FirstName
End Get
Set(ByVal Value As String)
m_FirstName = Value
End Set
End Property
|
|
This attribute is particularly useful for properties that represent objects. For example, you can use a file selection dialog to select an image but you cannot use the dialog to reset an image property to Nothing.
|
|
|
|
|
|