简体   繁体   English

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

[英]Need some help converting VB.NET code to C#

I have a CRC class written in VB.NET. 我有一个用VB.NET编写的CRC类。 I need it in C#. 我需要它在C#中。 I used an online converter to get me started, but I am getting some errors. 我使用在线转换器让我开始,但我收到一些错误。

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! 谢谢!

buffer(i)更改为buffer[i]

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

使用括号代替括号。

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

你使用括号而不是括号。

You need square brackets instead of round ones at the end of the second line. 你需要方括号而不是第二行末尾的圆括号。

^ buffer[i]; ^ buffer [i];

You want to change the () to []. 您想将()更改为[]。 Array indexing in C# is done using square brackets, not parentheses. C#中的数组索引使用方括号而不是括号来完成。

So 所以

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

it should be 它应该是

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

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”是一个字节数组,可以用C#中的方括号访问。 "buffer(i);" “缓冲器(I);” looks to the C# compiler like a method call, and it knows you have declared it as a variable. 像C#编译器一样调用方法调用,它知道你已经将它声明为变量。 Try "buffer[i];" 试试“buffer [i];” instead. 代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM