Skip to main content


Showing posts from March, 2011

Coding a Default Property

The concept of a "default property" for an object isn't what it used to be. Programmers new to VB.NET after 2001 (When VB6 was taken behind the barn and shot.) may not even be aware of how it used to be. In brief, you used to be able to write code like this:

TextBox1 = "Text"
This was really shorthand for ...

TextBox1.Text = "Text"
... because the Text property was the default property.
VB.NET continues to include a "Default" property attribute, but it's not at all the same. In fact, the way it's really used is documented in such an obscure way at Microsoft that there is a real need for some clarification.
The Microsoft documentation for declaring a Default Property in a Class definition is fairly straightforward. But you have to read the whole thing. The initial step-by-step instructions don't work. You could get the idea that all you have to do is simply use the Default keyword instead of Private, Public, or Shared.

Default …