Hoeist!? Blog of Colin Raaijmakers.

Hoeist!? Blog of Colin Raaijmakers.

VB.NET Option Strict and Option Explicit

Development

Option Explicit On forces you to declare all your variables, which makes your code easier to read and maintain. Be sure to use the As clause in every declaration, including procedure arguments. If you do not specify As, your variables and arguments take data type Object, which is usually not the optimal type. Using As improves performance because it moves type inference from run time to compile time. For more information, see Option Explicit Statement.

Option Strict On disallows implicit narrowing, requires the As clause in every declaration, and disallows late binding regardless of the Option Explicit setting. You can still perform narrowing type conversions, but you must use explicit conversion keywords such as CInt and CType. Explicit declaration improves performance because it protects your code from inadvertent late binding. For more information, see Option Strict Statement.

Option Compare Binary specifies that strings are to be compared and sorted based on the binary representation of their characters, without considering equivalent characters such as uppercase/lowercase pairs. You should use binary comparison whenever your application's logic permits it. It improves performance because the code does not need to deal with case insensitivity, or with groups of characters considered alphabetically the same in a given culture.

Read more about, VB.NET Option Strict and Option Explicit

Tags: vb.net, option, explicit, strict

Published: Friday, February 11, 2011

VB.NET Short Circuiting (AndAlso OrElse)

Development

When possible, you should use the short-circuiting Boolean operators, AndAlso and OrElse. These can save time by bypassing the evaluation of one expression depending on the result of the other. In the case of AndAlso, if the result of the expression on the left is False, the final result is already determined and the expression on the right is not evaluated. Similarly, OrElse bypasses the expression on the right if the one on the left evaluates to True. Note also that the Case statement can short-circuit a list of multiple expressions and ranges, if it finds a match value before the end of the list.

Read more about, VB.NET Short Circuiting (AndAlso OrElse)

Tags: vb.net, andalso, orelse

Published: Friday, February 11, 2011