我正在尝试将一些代码从C#转换为VB.NET,而我仍然坚持这一点。
C#代码:
static void test()
{
byte[] argss = new byte[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
short[] values = new short[argss.Length / 2];
for (int i = 0; i < argss.Length; i += 2)
{
values[i / 2] = (short)((argss[i + 1] << 8) | argss[i + 0]);
Console.WriteLine(values[i / 2]);
}
Console.ReadLine();
}
输出: 256 770 1284 1798 2312
VB.Net代码:
Sub Test()
Dim argss() As Byte = New Byte() {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Dim values(argss.Length / 2) As Short
Dim i As Integer = 0
While i < argss.Length
values(i / 2) = Convert.ToInt16(argss(i + 1) << 8 Or argss(i + 0))
Console.WriteLine(values(i / 2))
i += 2
End While
Console.ReadLine()
End Sub
输出: 1 3 五 7 9
答案 0 :(得分:0)
我认为问题在于这条线
Convert.ToInt16(argss(i + 1) << 8 Or argss(i + 0))
尝试将其更改为:
Console.WriteLine(CInt(argss(i + 1)) << 8 Or argss(i + 0))