Option Strict On

torg

Regular
Joined
Nov 7, 2002
Messages
60
Location
Norway
It`s been said that converting string variables to numeric variables and vice versa is bad programming practice, and that option strict on should be used. Why is that?
 
http://www.xtremedotnettalk.com/showthread.php?s=&threadid=71107

^ Look at the discussion there.

Option Strict simply prevents implicit conversion between data-types. You can still convert from String to Integer by doing it
like this:
Visual Basic:
'Int -> String
myString = Convert.ToString(myInt)

'String -> Int
myInt = Integer.Parse(myString)
But you can't do this:
Visual Basic:
myInt = myString
 
Option strict basically disallows any implicit conversions of data types. The reason for this, is that somewhere down the line (usually after you've already deployed the application), converting one type to another type might cause undesired results and hence, crashing your application. So with Option Strict On, you are not allowed to build your solution/project if you have implicit conversions. Try using CType(STRING, INT) or vice-versa, so you aren't implicitly converting data types.
 
Back
Top