

You cannot initialize the value of any nonshared data member of a structure as part of its declaration. You cannot have only constants, properties, and procedures, even if some of them are nonshared. You can declare zero or more nonshared variables or nonshared, noncustom events in a structure. The structure itself, however, can be Protected or Protected Friend. A structure member cannot be Protected or Protected Friend because nothing can inherit from a structure. You must declare every member of a structure. Instead, you must declare a variable of the nested structure's data type. However, you cannot access a nested structure's members through the containing structure. The outer structure is called the containing structure, and the inner structure is called a nested structure. You can define one structure within another. For more information, see Access levels in Visual Basic. You can adjust their access levels with the access modifiers. For more information, see Declaration Contexts and Default Access Levels. This means the declaration context for a structure must be a source file, namespace, class, structure, module, or interface, and cannot be a procedure or block. You can use Structure only at namespace or module level. For more information, see Structures and Classes. Also, classes are reference types and structures are value types. However, there are significant differences between structures and classes in areas such as inheritance, declarations, and usage. For example, structures can have properties and procedures, they can implement interfaces, and they can have parameterized constructors.


Structures support many of the same features as classes. A structure is a generalization of the user-defined type (UDT) of previous versions of Visual Basic. The Structure statement defines a composite value type that you can customize. Zero or more declarations of Function, Operator, Property, or Sub procedures, which serve as method members of the structure. Zero or more Const, Dim, Enum, or Event statements declaring data members of the structure. The names of the interfaces this structure implements. Required if you use the Implements statement. Indicates that this structure implements the members of one or more interfaces. List of type parameters for this structure. Specifies that this is a generic structure. Indicates a partial definition of the structure. Can be one of the following: - Public - Protected - Friend - Private - Protected Friend - Private Protected See Access levels in Visual Basic. Declares the name of a structure and introduces the definition of the variables, properties, events, and procedures that the structure comprises.
