将C#转换为VB.NET时的比较错误

时间:2011-01-21 19:28:20

标签: c# vb.net

我正在将一些c#代码转换为VB.NET代码...我在下面遇到错误

C#

if (bytes[i - 1] == ' ')
{
  returnValue.Append("=20");
}
else if (bytes[i - 1] == '\t')
{
  returnValue.Append("=09");
}

VB.NET

If bytes(i - 1) = " "C Then <==error Operator "=" is not defined for types 'Byte' and 'Char'

   returnValue.Append("=20")
ElseIf bytes(i - 1) = ControlChars.Tab Then <==error Operator "=" is not defined for types 'Byte' and 'Char'
   returnValue.Append("=09")
End If

2 个答案:

答案 0 :(得分:1)

我认为实际问题在于初步比较。您正在尝试将bytechar进行比较。首先尝试将byte转换为char

if char(bytes(i - 1)) = " "C Then

答案 1 :(得分:1)

尝试使用

Convert.ToChar(bytes(i - 1)) = " "C

bytes(i - 1) = Convert.ToByte(" "C)