Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleUse the DefaultValue attribute in VB .NET
DescriptionThis example shows how to use the DefaultValue attribute in VB .NET.
KeywordsDefaultValue, DefaultValueAttribute, attribute, VB.NET, property
CategoriesVB.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.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated