I was tasked with converting a solution from VB to C#. There were 22 projects and hundreds of classes, so I decided to research converters. I finally settled on SharpDevelop, which is an IDE with an included converter. I ran it on each of my projects, and have plenty of errors to fix, but I should be able to go through them and hopefully figure them out. The main issue I am having is with the summary log. I have hundreds of lines for various classes reading:
-- line 0 col 0: Case labels with binary operators are unsupported : Equality
-- line 0 col 0: Case labels with binary operators are unsupported : Equality
-- line 0 col 0: Case labels with binary operators are unsupported : Equality
-- line 0 col 0: Case labels with binary operators are unsupported : Equality
-- line 0 col 0: Case labels with binary operators are unsupported : Equality
I've looked this up, but am not finding a good explanation on what it really means or how to correct it. most of what I find are lines of commented code that say something like:
// ERROR: Case labels with binary operators are unsupported : LessThan
40:
Could someone please provide a bit more information on what causes this error means and how to correct it. Thank you.
It means that in C# there is no equivalent for Case Is =
(part of a Select Case
in VB)... Except of course that there really is.
You can rewrite:
Case Is = 999
as
case 999:
in C#.
There is really no equivalent for Case Is <
though, you'll have to rewrite that with if
.
Select
in VB.NET has pretty more complex syntax than its C# counterpart, there is nothing you can do so you have to rewrite your Select
statements into if
/else
:
Select myVariable
Case 1
' Do #1
Case 2, 3
' Do #1
Case Is < anotherValue
' Do #3
End Select
You have to rewrite to:
if (myVariable == 1)
; // #1
else if (myVariable == 2 || myVariable == 3)
; // #2
else if (myVariable < anotherValue)
; // #3
In general with C# switch
you can only test for equality (that's the warning you get) so for anything else you have to go back to a plain if
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With