Why doesn't compiler error on build?

161 Views Asked by At

I am using VB.NET, at the top is

Option Explicit

However why does the compiler not raise an error when I do :-

obj.ThisFunction(Convert.ToInt32(strMessage))

and the function is :-

Function ThisFunction(id as long)

Surely, Int32 is int and int64 is long? Is there a compiler option in VS 2013 that I can turn on to spot these?

1

There are 1 best solutions below

0
On

This is not a compile error. If you have written code to explicitly convert strMessage to an Int32, then the compiler assumes you knew what you were doing here.

In order to check this is actually an Int32 you can use Int32.TryParse

Converting an Int32 to an Int64 is not a compile error even with Option Strict On because this is a widening conversion (Option Strict On gives a compilation error when it finds implicit narrowing conversions, amongst other things)