Skip to Content
Programming Visual Basic .NET, Second Edition
book

Programming Visual Basic .NET, Second Edition

by Jesse Liberty
April 2003
Intermediate to advanced
560 pages
14h 4m
English
O'Reilly Media, Inc.
Content preview from Programming Visual Basic .NET, Second Edition

Whitespace

In the Visual Basic .NET language, spaces and tabs are considered to be "whitespace” (so named because you see only the white of the underlying “page”). Extra whitespace is generally ignored in Visual Basic .NET statements. Thus, you can write:

myVariable = 5

or:

myVariable    =                        5

and the compiler will treat the two statements as identical. In fact, Visual Studio .NET will automatically discard the extra white space and close up the second version so that it resembles the first!

The exception to this rule is that whitespace within strings is not ignored. If you write:

Console.WriteLine("Hello World")

each space between “Hello” and “World” is treated as another character in the string.

Most of the time the use of whitespace is intuitive. The key is to use whitespace to make the program more readable to the programmer; the compiler is indifferent.

However, there are instances in which the use of whitespace is quite significant. Although the expression:

Dim x As Integer = 5

is the same as:

Dim x As Integer=5

it is not the same as:

Dimx As Integer = 5

The compiler knows that the whitespace on either side of the assignment operator is extra, but the whitespace between the keyword Dim and the identifier x is not extra, and is required. This is not surprising; the whitespace allows the compiler to parse the keyword Dim rather than some unknown term Dimx. You are free to add as much or as little whitespace between Dim and x as you care to, but there must be at least one whitespace character ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Visual Basic .NET

Programming Visual Basic .NET

Dave Grundgeiger
VB.NET Language in a Nutshell, Second Edition

VB.NET Language in a Nutshell, Second Edition

Steven Roman PhD, Ron Petrusha, Paul Lomax

Publisher Resources

ISBN: 0596004389Supplemental ContentCatalog PageErrata