description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: Default (Visual Basic) |
Default |
07/20/2015 |
|
|
45fce9b9-d212-4b2d-ab86-6e359b8b57af |
Identifies a property as the default property of its class, structure, or interface.
A class, structure, or interface can designate at most one of its properties as the default property, provided that property takes at least one parameter. If code makes a reference to a class or structure without specifying a member, Visual Basic resolves that reference to the default property.
Default properties can result in a small reduction in source code-characters, but they can make your code more difficult to read. If the calling code is not familiar with your class or structure, when it makes a reference to the class or structure name it cannot be certain whether that reference accesses the class or structure itself, or a default property. This can lead to compiler errors or subtle run-time logic errors.
You can somewhat reduce the chance of default property errors by always using the Option Strict Statement to set compiler type checking to On
.
If you are planning to use a predefined class or structure in your code, you must determine whether it has a default property, and if so, what its name is.
Because of these disadvantages, you should consider not defining default properties. For code readability, you should also consider always referring to all properties explicitly, even default properties.
The Default
modifier can be used in this context: