Default Properties

Visual Basic language enables defining default properties. A default property is a property marked with the Default keyword that enables assignments to the objects defining the property without the need of invoking the property itself. Default properties are strictly related to data arrays and collections of objects, because they provide the ability of managing an index. For example, imagine you have an array of strings defined within a class as follows:

Private listOfNames() As String = _     {"Alessandro", "Del Sole", "VB 2010 Unleashed"}

A default property enables easy access to such an array, both for reading and writing. The following code demonstrates how you can implement a default property:

Parameters Types

The preceding ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.