This documentation is archived and is not being maintained.

User-Defined Data Type

The user-defined type (UDT) supported by previous versions of Visual Basic is generalized to a structure in Visual Basic .NET. A structure is a concatenation of one or more members of various data types. The structure is treated as a single unit, although its members can also be accessed individually.

A structure declaration starts with the Structure statement and ends with the End Structure statement. The Structure statement supplies the name of the structure, which is also the identifier of the data type being defined by the structure. Other parts of the code can use this identifier to declare the data type of variables, arguments, and function return values.

The following paradigm shows the declaration of a structure.

[Public | Protected | Friend | Protected Friend | Private] Structure structname
   {Dim | Public | Friend | Private} member1 As datatype1
   {Dim | Public | Friend | Private} memberN As datatypeN
End Structure

The declarations between the Structure and End Structure statements define the members of the structure. Every member must be declared using a Dim statement or a statement that specifies access, such as Public, Private, or Friend. If a Dim statement is used, the access defaults to public.

Note   As with all composite data types, you cannot safely calculate the total memory consumption of a structure by adding together the nominal storage allocations of its members. Furthermore, you cannot safely assume that the order of storage in memory is the same as your order of declaration.

All structures inherit from the .NET class System.ValueType.

See Also

Data Type Summary | ValueType Class | Structures: Your Own Data Types | Efficient Use of Data Types | Structure Statement