Numbers can be shifted with the <<
and >>
operators, but the right operand of
the operation needs to be an int
or a type that has an implicit
conversion to int
. However, when the left operand is an object
, the compiler’s type checking is turned off, therfore you
can pass anything to the right of a shift operator and have it compile. If the argument can’t be implicitly converted to int
at runtime,
a RuntimeBinderException will be
raised.
Dim o As Object = 5
Dim x As Integer = 5
x = o >> 5 ' Noncompliant
x = x << o ' Noncompliant
Exceptions
This rule does not raise when the left or the right expression is Nothing.
x = Nothing >> 5
x = 5 << Nothing