Option infer,option strict,option compare,option explict in vb.net

Pluralsight courses
LinkedIn Premium uses PayScale to estimate job salaries

Premium (Not Free) Video Tutorials

Free Video Tutorials & Free Tools

Sources :

About.com, Google.com and my knowledge

Back to the Future – VB6 Variant Redux?

In VB6, we could use a variable without declaring it as …

myVar1 = "whatever"
myVar2 = 666

The variables were compiled as Variant types, which could hold anything.

This was carried over into .NET as Object types. If Option Explicit is Off, then you can write the same code and the variables became Object types. Again, they could hold anything. But the default changed in .NET (Option Explicit is On by default) and we were strongly encouraged to declare everything. Not only did it help the compiler catch errors so the application didn't crash at runtime, but the code ran faster because the variables were "early bound" instead of "late bound". With late binding, the compiler has to add code to figure out what a variable is before using it and that slows everything down. VB 6 was slower for the same reason.

The Option Strict statement

By default, the Visual Basic .NET or Visual Basic compiler does not enforce strict data typing. To change this default behavior, see the Change the Default Project Values section.

Option Strict restricts implicit data type conversions to only widening conversions. Widening conversions explicitly do not permit any data type conversions in which data loss may occur and any conversion between numeric types and strings. For more information about widening conversions, see the Widening Conversions section.

When you use the Option Strict statement, the statement must appear before any other code. In Visual Basic .NET, you can typically convert any data type to any other data type implicitly. Data loss can occur when the value of one data type is converted to a data type with less precision or with a smaller capacity. However, you receive a run-time error message if data will be lost in such a conversion. Option Strict notifies you of these types of conversions at compile time so that you can avoid them.

For Option Compare please visit :  http://msdn.microsoft.com/en-us/library/8t3khw5f(v=vs.80).aspx

If you have got any suggestions and comments plase let us know

Related posts:

  1. Compare Date – SQL Server Syntax Example: Compare Date – T-SQL Example Compare Date - SQL Server Syntax Example: Compare Date -...
  2. SQL Server 2005 Express Tutorial: (13 Videos) Database mirroring, backup sql server 2005, sql server 2005 replication, sql server standard edition, download sql server 2005, compare sql server, sql server instance Excellent SQL Server 2005 Express series of 13 free videos...
  3. vb competition I recently went to a vb competition and i was...
  4. What is .NET Framework? A Visual Definition The .NET applications and services operate within the .NET Framework...

Related posts brought to you by Yet Another Related Posts Plugin.

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

Powered by WP Hashcash

This blog uses the cross-linker plugin developed by Web-Developers.Net