Learn to program in Visual Basic .NET, the right way

The Basics - Comments

What are Comments?

A comment is a portion of text that a programmer writes and the Visual Basic .NET compiler ignores.

Usage

Comments have many uses, and in my opinion, no code is good code without comments! The follow is a list of possible uses for comments:

  1. Notation: Notate who the author of the code is, when the code was written, and/or the version of the framework that the code targets.
  2. Explination: Explain what a particular line or block of code does.
  3. Indication: Indicate that a piece of code may be inefficient and/or incomplete.
  4. Signals: Signal the line of code that may be causing an error.

Location

A comment can appear anywhere in your code; comments can be on their own line or they can come after some code is executed.

It is important to know that a comment ends whenever it reaches a new line or whenever it reaches the line terminator character and there is no way to prematurely end a comment.

The following is an example of how a comment is used:

Fiddle: Live Demo

Remarks

Comments may make the code look bigger, but they do not actually add to the final size of the program. Comments are completely stripped out of the code whenever the code runs through the compiler. You should not worry about the overall code length with comments as they have no impact on the size in the long run.