Chapter 11. Fields and Properties

The previous chapter discussed executable statements (methods) as type members, so now it is worth talking about variables as type members. Like local variables, which are locations to store information in methods, fields and properties are locations that store information in classes or structures.

Fields

A field is a variable that lives in a class or a structure instead of inside a method. Fields are declared in exactly the same way that local variables are declared.

Module Test
  Dim x As Integer
  Dim y As Long = 5
  Dim z(5) As Integer
End Module

Instance fields live as long as the class or structure that contains them lives, while shared fields live for the length of the program's execution. Fields declared in modules ...

Get Visual Basic .NET Programming Language, The 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.