我需要转换一堆VB。NET代码转换为C#。Instant C#是一个很好的帮手,但有一个方面。。。字符串不区分大小写。NET代码。
例如,将测试例程更改为Test2例程的代表,然后转换为C#。
Option Compare Text
.
.
.
Private Sub Test()
Dim x as string = "x"
Dim y as string = "y"
If x = y then msgbox("They match")
End Sub
Private Sub Test2()
Dim x as string = "x"
Dim y as string = "y"
If String.Compare(x, y, StringComparison.CurrentCultureIgnoreCase) = 0 then msgbox("They match")
End Sub
C#转换后的输出如下
private static void Test()
{
string x = "x";
string y = "y";
if ((x ?? string.Empty) == (y ?? string.Empty))
{
MessageBox.Show("They match");
}
}
private static void Test2()
{
string x = "x";
string y = "y";
if (string.Compare(x, y, StringComparison.CurrentCultureIgnoreCase) == 0)
{
MessageBox.Show("They match");
}
}
private static void Test()
{
string x = "x";
string y = "y";
if (string.Equals(x ?? string.Empty, y ?? string.Empty, StringComparison.OrdinalIgnoreCase))
{
MessageBox.Show("They match");
}
}