从VB转换为C#

我的任务是将解决方案从VB转换为C#。 有22个项目和数百个课程,所以我决定研究转换器。 我最终选择了SharpDevelop,这是一个带有转换器的IDE。 我在每个项目上运行它,并且有很多错误需要修复,但是我应该能够通过它们并希望能够解决它们。 我遇到的主要问题是摘要日志。 我有数百行各种课程阅读:

-- 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 

我已经看了这个,但是我没有找到关于它的真正含义或如何纠正它的好解释。 我发现的大多数是注释代码行,如下所示:

 // ERROR: Case labels with binary operators are unsupported : LessThan 

40:

有人可以提供更多信息,说明导致此错误的原因以及如何纠正错误。 谢谢。

这意味着在C#中没有Case Is = (VB中的Select Case一部分)的等价物……除了当然确实存在。

你可以改写:

 Case Is = 999 

 case 999: 

在C#中。

对于Case Is <来说,确实没有相应的东西Case Is <但是,你必须用if重写它。

在VB.NET中Select具有比其C#版本更复杂的语法,没有什么可以做的,因此您必须将Select语句重写为if / else

 Select myVariable Case 1 ' Do #1 Case 2, 3 ' Do #1 Case Is < anotherValue ' Do #3 End Select 

你必须改写为:

 if (myVariable == 1) ; // #1 else if (myVariable == 2 || myVariable == 3) ; // #2 else if (myVariable < anotherValue) ; // #3 

通常使用C# switch您只能测试相等性(这是您得到的警告),所以对于其他任何东西,您必须返回到平原if