Declaring and Initializing Variables

There is one significant difference in the way you write declarations for simple types and object types. That difference is the use of the keyword New. (We'll look at New more in the section “Using Objects.”)

Variables can be declared and initialized in Visual Basic .NET on a single line. In addition to resulting in fewer lines of code, this new feature can be applied with some simple rules to make code more robust.

Before we look at several declarative statements, here is an overview of the best practices regarding variables that we will follow throughout this book:

  • Always provide an initial value for variables.

  • Declare and initialize variables in a single statement.

  • Declare variables immediately before they ...

Get Visual Basic® .NET Unleashed 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.