VB.NET: Is there a way to keep Nothing from defaulting to 0 for number types?

It really seems to me that the VS 2010 IDE is not barking at me, trying to pass Nothing through a method parameter that accepts a user-defined enumeration. Instead, it goes from 0 to the method. C # would never allow this. Can I add a module level modifier, for example option strict, that will force the IDE to prevent these types of implicit conversions?

+5
source share
2 answers

Unfortunately no.


0 ( None - ) , , .

Sub Main
    MyMethod(Nothing) ' throws Exception
End Sub

Sub MyMethod(e as MyEnum)
    If e = 0 Then
        Throw New Exception
    End If
End Sub

Enum MyEnum
    a=1
    b=2
    c=3
End Enum
+6

#. .

. . , , #. , VB.NET , #. Nothing. Cringe- #, , VB.NET.

+3

All Articles