my_object.MyVar = 1 ' Compilation Error
:
my_object.MyVar MyEnum 1 Integer (Byte/UShort/Etc.) , Option Strict On. :
my_object.MyVar = MyEnum.SECOND
' .SECUND should mean "1" as FIRST would be "0" by default..
? "1" Byte, " " enum..! , () Option Strict . Strict Off ! , Option Strict On :
Dim MyByteVar As Byte = 1 ' No compilation error
MyByteVar Byte , "1" Integer. , MyByteVar Byte, "1" , . .
. "1" MyEnum Strict On, , 1 , , . , , MSDN Option Strict.. , " " , :
, , .
(Integer → Byte) Explicit On.
EDIT 2: ^^ , :/, , , -..
Enumerations, Option Strict Option Explicit, Dim my_var As MyEnum = 1. , / , , , , -.
If my_object.MyVar = 1 Then
' my_object.MyVar = MyEnum.FIRST = 0 -> Byte (strongly typed)
' 1 -> Integer by default
' Convert my_object.MyVar to Integer (always a widening conversion)
' 0 is different from 1 (Integer to Integer comparison)
' -> FALSE - No compilation error
If my_object.MyVar = 27 Then
' Same as above and will return FALSE
If my_object.MyVar = 3.141
' my_object.MyVar = MyEnum.FIRST = 0 -> Byte (strongly typed)
' 3.141 -> will default to Double (because you didn't used Type Character flag)
' Convert my_object.MyVar to Double (always a widening conversion)
' 0 is different from 3.141 (Double to Double comparison)
' -> FALSE - No compilation error
my_object.MyVar MyEnum.SECOND, TRUE:
If my_object.MyVar = 1
' my_object.MyVar = MyEnum.SECUND = 1 -> Byte (strongly typed)
' 1 -> will default to Integer
' Convert my_object.MyVar to Integer = 1
' 1 = 1 => TRUE !
, :
If my_object.MyVar = "Fred" Then '...
Strict On, Double String . , Strict . Double, Byte? , . Byte → Integer → Long → .. → Double.
shoud my_object.MyVar String, "Fred" . ( ), Option Strict On.
, . , . , , Strict, , , , .
= > /, ?
= > Byte → Double , Strict ?
, ...