Chapter 5: Creating and Building Projects | 135 |
Figure 5-11 The VB Compile Options page
Most of the VB and C# compiler options are similar, except for Option Explicit, Option Strict, Option Compare, and Option Infer. In VB, variable declaration before use can be turned off. When Option Explicit is on, you must declare any variables before use. You can also assign any type to another by default, but Option Strict, if turned on, will force you to use code that performs a conversion from a larger type to a smaller type, often referred to as a narrowing conversion.
Option Compare causes comparison of strings to be done in a binary fashion. However, when working with different languages, you’ll want to consider changing Option Compare to text so that the comparison will consider
Dim studentName = "Joe"
In this example, the type of "Joe" is clearly a String. Since Option Infer is turned on, this syntax is valid and studentName becomes a String because that is the type of the value being assigned.