Declares the names of properties and the procedures called when storing and retrieving values.
[ modifier ] Property declarator [ , declarator ]... [ Does trait_name . old_name ]
[ modifier ] Property declarator [ Begin parameter_list ] [ Get [ statements] ] [ Set parameter [ statements] ] End [ Property ]
- Optional, between square brackets:
- Abstract – The property contains no implementation and must be overridden in a concrete subclass.
- Backed – The property is backed. The one-line construction is always backed.
- Deprecated – The property is deprecated. See Deprecated for more information.
- Final – The property cannot be overridden in a subclass.
- Override – The property is a re-implementation of a property inherited from a superclass.
- ReadOnly – The property is read-only. It must have a Get handler. It cannot have a Set handler.
- Shared – The property is owned by the enclosing class and not an instance of that class.
- WriteOnly – The property is write-only. It must have a Set handler. It cannot have a Get handler.
- You can put Abstract together with ReadOnly or WriteOnly. You can put Backed and Deprecated together with any other modifiers.
- Necessary. One or more declarative clauses that have a similar syntax to the Dim statement.
The one-line construction permits multiple declarators with a comma between each.
name [ ( [ dimensions ] ) ] [ As type | In unit ] [ = initializer ]
- Necessary identifier or object handle
- Optional. One or more integer expressions separated by commas. Not permitted on unbacked properties.
- Optional data type
- Optional unit of measure
- Optional expression having a data type compatible with type or unit.
- Optional in the many-line construction. Allows you to specify that the property is an array.
- Necessary after Begin. A list of integer parameters, separated by commas, which hold the array indices supplied by the caller.
- Marks the start of a procedure that is called when retrieving the current value of the property.
- Marks the start of a procedure that is called when storing a new value in the property.
- Necessary after Set. It must be the same data type as the property. If you do not specify a data type, the type of the property is assumed.
- Completes the many-line construction. You can also use End Property.
A property, like a method, has public visibility. You may declare a property anywhere a method is permitted, namely, in modules, classes, and traits.
A property can have one of two constructions: a one-line construction or a many-line construction.
The one-line construction is always backed. A backed property automatically allocates memory with every instance of its owner.
The many-line construction is usually not backed. A backed property automatically allocates memory with every instance of its owner. If you need a backed property, use the modifier Backed.
Class Person Property Name As String End Class Person #person #person.Name = "John Doe" #Debug.PrintLine #person.Name
One-line array property
Class Person Const MaxAddresses = 2 Property Address(MaxAddresses) As String End Class
Many-line property, backed
Class Person [Backed] Property Name As String Get ' do something Set value ' do something End Property End Class ' do something
Many-line property, not backed
Class Person Property Name As String Get ' do something Set value ' do something End Property End Class ' do something