VB -> C#: Select Case [object]
can have incorrect converted code
#1100
Labels
output logic error
A bug where the converted output behaves differently to the input code
VB -> C#
Specific to VB -> C# conversion
VB.Net input code
Erroneous output
Expected output
Note with
Option Strict On
the VB.NET example doesn't compile.The issue is, in C#
default
branch is executed.Cast to
int
(=type of the cases) fixes it.Changing the expression into
(int)o
can result in runtime errors in case the object can't be converted to anint
, which would be better than executing wrong branch without errors.On the other hand, something like
(o is int ? (int)o : o)
would work correctly (I thinkmost of the time*), but would require introducing temporary variable (in caseo
is a property, an invocation, or an index access - do I have them all?)*)
o = "2"
is same as2
, which is a problem. The code decompiled to C# usesOperators.ConditionalCompareObjectEqual(o, 1, false)
Details
The text was updated successfully, but these errors were encountered: