Anders
Anders

Reputation: 12560

Need some help converting VB.NET code to C#

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.

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'

Any ideas how I could fix this?

Thanks!

Upvotes: 2

Views: 229

Answers (8)

R Ubben
R Ubben

Reputation: 2204

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.

Upvotes: 0

messenger
messenger

Reputation: 614

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

Upvotes: 10

FlappySocks
FlappySocks

Reputation: 3880

it should be

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

Upvotes: 5

Sean
Sean

Reputation: 4470

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

So

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

Upvotes: 5

Eifion
Eifion

Reputation: 5553

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

^ buffer[i];

Upvotes: 5

Robert Greiner
Robert Greiner

Reputation: 29722

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

you used parenthesis instead of brackets.

Upvotes: 5

Matthew Jones
Matthew Jones

Reputation: 26190

Use brackets instead of parentheses.

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

Upvotes: 7

John Rasch
John Rasch

Reputation: 63435

Change buffer(i) to buffer[i]

Upvotes: 12

Related Questions