This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!
Structure Statement
Used to create a user-defined class containing one or more elements of a class.
[Public|Private|Friend] Structure varname
NonMethod Declarations
Method Declarations
End Structure
The Structure statement syntax has these parts:
Part |
Description |
Public |
Optional. Entities declared with the Public modifier have public access. There are no restrictions on the use of public entities |
Private |
Optional. Entities declared with the Private modifier have private access. A private entity is accessible only within its declaration context, including any nested entities. |
Friend |
Optional. Entities declared with the Friend modifier have friend access. An entity with friend access is accessible only within the program that contains the entity declaration. |
varname |
Required. Name of the user-defined type; follows standard naming conventions. |
Remarks
Structures support many of the same features of classes. For example, structures support the ability to define properties, methods, and events with each member defined with either private, friend, or public accessibility. Structures can implement interfaces and handle events. Structures can have parameterized constructors.
The following features of classes are not supported by structures:
- structures can not explicitly inherit from another type; however they implicitly inherit the methods of the Object class
- structures can not be inherited from; i.e. all structures are implicitly “CantInherit”
- it is illegal to define a parameterless constructor for a structure; a parameterless constructor is implicitly defined for a class that initializes all the structure’s data members to their default value
- it is illegal to define a destructor for a structure
- the declarations of data members of a structure can not include initializers nor can they use the “As New <type>” declaration syntax or specify an initial size for an array
- structures are value types rather than reference types
- the default accessibility level of data member declarations in structures is Public rather than Private as it is for classes and modules.
The fact that structures are value types rather than reference types are reflected in their use rather than their declaration. Specifically:
- a variable or data member that is declared to be a structure implicitly includes an initialization of the structure via the parameterless constructor. I.E. “Dim s As Struct1” is equivalent to “Dim s As Struct1 = New Struct1()”
- assigning a structure instance or passing a structure instance to a byval parameter causes the structure to be copied
- equality testing is performed by a field by field equality test
Note that structures do not support the data member declaration syntax supported by UDTs where the statement simply contained the variable name and an As clause without an initial “Dim” or “Public”.
See Also