defaultValueAttribute

M

Mike G.

I have a dumb question: What does the defaultvalue attribute do?

The help system says that it "Specifies the default value for a property",
and provides the following as an example:

Private MyVar as Boolean = False
<DefaultValue(False)> _
Public Property MyProperty() As Boolean
Get
Return MyVar
End Get
Set
MyVar = Value
End Set
End Property

It seems to me that MyProperty has a default value of false because of the
first line:
Private MyVar as Boolean = False

So, what exactly does DevaultValue(False) do?

Thanks!

Mike
 
J

Jorge Matos

Its an attribute that the VS.NET IDE looks at when displaying your custom
property in the properties window. If the attribute is found, the designer
will display your property with the value specified by the attribute.
 
M

Mike G.

Thanks Jorge,

I created a new web control library project to test this. I had one
property that did not specify the defaultvalue attribute, but gave the
property a default value by assigning a value to the private variable. That
value correctly displayed in the IDE. I then added the defaultvalue
attribute and assigned it a different value. There was no change in the
IDE. Am I missing something?

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top