需要一些帮助将VB.NET代码转换为C#

时间:2022-09-01 11:32:25

I have a CRC class written in VB.NET. I need it in C#. I used an online converter to get me started, but I am getting some errors.

我有一个用VB.NET编写的CRC类。我需要它在C#中。我使用在线转换器让我开始,但我收到一些错误。

byte[] buffer = new byte[BUFFER_SIZE];
iLookup = (crc32Result & 0xff) ^ buffer(i);

On that line, the compiler gives me this error:

在那一行,编译器给了我这个错误:

Compiler Error Message: CS0118: 'buffer' is a 'variable' but is used like a 'method'

编译器错误消息:CS0118:'buffer'是'变量'但是像'方法'一样使用

Any ideas how I could fix this?

我有什么想法可以解决这个问题?

Thanks!

8 个解决方案

#1


Change buffer(i) to buffer[i]

将缓冲区(i)更改为缓冲区[i]

#2


Change buffer(i) to buffer[i] as VB array descriptors are () and C# array descriptors are [].

将缓冲区(i)更改为缓冲区[i],因为VB数组描述符是(),而C#数组描述符是[]。

#3


Use brackets instead of parentheses.

使用括号代替括号。

iLookup = (crc32Result & 0xff) ^ buffer[i];

#4


buffer[i];  //not buffer(i)

you used parenthesis instead of brackets.

你使用括号而不是括号。

#5


You need square brackets instead of round ones at the end of the second line.

你需要方括号而不是第二行末尾的圆括号。

^ buffer[i];

#6


You want to change the () to []. Array indexing in C# is done using square brackets, not parentheses.

您想将()更改为[]。 C#中的数组索引使用方括号而不是括号来完成。

So

iLookup = (crc32Result & 0xff) ^ buffer[i];

#7


it should be

它应该是

iLookup = (crc32Result & 0xff) ^ buffer**[i]**

iLookup =(crc32Result&0xff)^ buffer ** [i] **

#8


I assume there are some lines missing between these two? Otherwise, you are always going to be doing an XOR with zero...

我假设这两个之间缺少一些线?否则,你总是会做零的异或......

"buffer" is a byte array, and is accessed with the square brackets in C#. "buffer(i);" looks to the C# compiler like a method call, and it knows you have declared it as a variable. Try "buffer[i];" instead.

“buffer”是一个字节数组,可以用C#中的方括号访问。 “缓冲器(I);”像C#编译器一样调用方法调用,它知道你已经将它声明为变量。试试“buffer [i];”代替。

#1


Change buffer(i) to buffer[i]

将缓冲区(i)更改为缓冲区[i]

#2


Change buffer(i) to buffer[i] as VB array descriptors are () and C# array descriptors are [].

将缓冲区(i)更改为缓冲区[i],因为VB数组描述符是(),而C#数组描述符是[]。

#3


Use brackets instead of parentheses.

使用括号代替括号。

iLookup = (crc32Result & 0xff) ^ buffer[i];

#4


buffer[i];  //not buffer(i)

you used parenthesis instead of brackets.

你使用括号而不是括号。

#5


You need square brackets instead of round ones at the end of the second line.

你需要方括号而不是第二行末尾的圆括号。

^ buffer[i];

#6


You want to change the () to []. Array indexing in C# is done using square brackets, not parentheses.

您想将()更改为[]。 C#中的数组索引使用方括号而不是括号来完成。

So

iLookup = (crc32Result & 0xff) ^ buffer[i];

#7


it should be

它应该是

iLookup = (crc32Result & 0xff) ^ buffer**[i]**

iLookup =(crc32Result&0xff)^ buffer ** [i] **

#8


I assume there are some lines missing between these two? Otherwise, you are always going to be doing an XOR with zero...

我假设这两个之间缺少一些线?否则,你总是会做零的异或......

"buffer" is a byte array, and is accessed with the square brackets in C#. "buffer(i);" looks to the C# compiler like a method call, and it knows you have declared it as a variable. Try "buffer[i];" instead.

“buffer”是一个字节数组,可以用C#中的方括号访问。 “缓冲器(I);”像C#编译器一样调用方法调用,它知道你已经将它声明为变量。试试“buffer [i];”代替。