tags:

views:

41

answers:

1

I accidently wrote some code today that was like this:

Private Sub Foo()
    Dim i as Nullable(Of Integer)
    Bar(i)
End Sub

Private Sub Bar(myInt as Integer)
    ''//Do Stuff
End Sub

I immediately noticed the issue, but I had already hit the run button. It compiled successfully, I ran it through to the section and it threw an exception.

You can't do this in C#, it gives a compile error "cannot convert from 'int?' to 'int'".

Is there an 'Option Explicit' type switch that I can turn on to ensure that this sort of error does not occur again?

+4  A: 
Option strict on

link: http://msdn.microsoft.com/en-us/library/zcd4xwzs%28VS.80%29.aspx

shahkalpesh
Turn option strict on. Go into your Visual Studio settings and tell it to set it by default in all new code.
MarkJ