Subscribe to Subscribers
Talk to Webmaster Tony John

Resources » .NET programming » Visual Studio

What is the need of Option Strict On in VB.NET ?


Posted Date:     Category: Visual Studio    
Author: Member Level: Silver    Points: 7


The advantage of using OPTION STRICT ON is that it makes the code strongly typed. So it allows implicit data conversions for widening conversions only. Thus it results in no data loss. Also, conversion between numeric types and strings are also avoided



 


Use of Option Strict On


When programming in VB.NET, you should always do OPTION STRICT ON.

By default, VB.NET has OPTION STRICT OFF. So the program will do implicit type conversions and late bindings which leads to performance problems and run-time errors. Also, it will be difficult to understand the code later on. So it is a sub standard programming practice.

The advantage of using OPTION STRICT ON is that it makes the code strongly typed. So it allows implicit data conversions for widening conversions only. Thus it results in no data loss. Also, conversion between numeric types and strings are also avoided

Widening Conversions


Widening conversions means...

Byte can be converted to Byte, Short, Integer, Long, Decimal, Single, Double

Short can be converted to Short, Integer, Long, Decimal, Single, Double

Integer can be converted to Integer, Long, Decimal, Single, Double

Char can be converted to Char, String

and so on..
but integer cannot be converted to byte. (here, not from right to left)


How to set the option strict on in visual studio?



Go to Tools -> Options -> Projects & Solutions -> VB Defaults -> Set Option Strict On





Did you like this resource? Share it with your friends and show your love!


Responses to "What is the need of Option Strict On in VB.NET ?"
Author: Preethu    30 May 2012Member Level: Silver   Points : 0
It speeds up the code also.


Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: How to convert xml file to Excel file (.xlsx)
    Previous Resource: How to drag and drop multiple rows from xtragrid to xtratreelist in VB.NET?
    Return to Resources
    Post New Resource
    Category: Visual Studio


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Need of Option Strict On  .  VB.NET  .  
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.