C# & VB.NET Conversion Pocket Reference
always set this option to On, and it is now (actually for the
first time in VB’s history) set to On by default. There is no
equivalent in C# for this feature.
The second setting is Option Strict. This is a new setting for
VB developers. If you set Option Strict to Off, you do not
need to assign a type to your variables. In other words, it is
perfectly legal to write code that says:
Dim Acct = New CChecking( )
In that case, Acct will be of type System.Object. This feature
has two other side effects. One is that with Option Strict On,
the compiler will issue a compile-time error if it detects a nar-
rowing conversion or if it cannot guarantee that the conver-
sion will succeed. The developer can fix the error by using an
explicit cast. In VB explicit casts are done with the CType
function or an equivalent. (See “Type Comparison and Con-
version” in the “Syntax Differences” section for a full expla-
nation.) The only reason this option should be set to off is to
use late binding (see “Late Binding (VB)” in the “Unique
Language Features” section for details).
The third option in VB.NET, Option Compare, was
explained in detail in the “String Comparisons” section.
Errors and Warnings
Both compilers generate errors (of course), and both gener-
ate warnings as well, but the C# compiler can generate dif-
ferent types of warnings. Warnings come in different levels, 0
through 4. Warning level 0 means that no warnings are
reported. Warning level 1 means that only severe warnings
are reported.
VB.NET projects let you set the warning level to either 0 or
1. This is controlled through Project Properties
tion Properties
Build Enable build warnings (checked by
default). C# lets you set the warning level through Project
Configuration Properties Build Warning

Get C# & VB.NET Conversion Pocket Reference 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.