从VB转换为C#

Tim*_*Tim 5 .net c# vb.net sharpdevelop converter

我的任务是将解决方案从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
Run Code Online (Sandbox Code Playgroud)

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

// ERROR: Case labels with binary operators are unsupported : LessThan
Run Code Online (Sandbox Code Playgroud)

40:

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

Roy*_*tus 6

这意味着在C#中没有等效的Case Is =(Select CaseVB中的一部分)......除了当然确实存在.

你可以改写:

Case Is = 999
Run Code Online (Sandbox Code Playgroud)

case 999:
Run Code Online (Sandbox Code Playgroud)

在C#中.

实际上没有相应的东西Case Is <,你必须用它重写if.


Adr*_*tti 6

Select在VB.NET中,语法比C#语言复杂得多,没有什么可以做的,所以你必须将Select语句重写为if/ else:

Select myVariable
    Case 1
        ' Do #1 
    Case 2, 3
        ' Do #1
    Case Is < anotherValue
        ' Do #3
End Select
Run Code Online (Sandbox Code Playgroud)

你必须改写为:

if (myVariable == 1)
    ; // #1
else if (myVariable == 2 || myVariable == 3)
    ; // #2
else if (myVariable < anotherValue)
    ; // #3
Run Code Online (Sandbox Code Playgroud)

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