views:

116

answers:

8

Hey SO,

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!

+11  A: 

Change buffer(i) to buffer[i]

John Rasch
Dammit! Beat me by seconds! +1
Matthew Jones
same, i need to learn to type faster... +1 to you both.
Robert Greiner
The Aaron Burr effect as I will call it. It sounds much more compact than "Fastest gun in the west"
John Rasch
More like the Beat Jon Skeet effect.
Matthew Jones
@Matthew Jones: yeah, except he gets more rep than you even if he answers the question 10 days after it was posted. He transcends quickness.
Robert Greiner
If you have five answers and Jon Skeet has five answers, Jon Skeet has more rep than you.
Matthew Jones
+7  A: 

Use brackets instead of parentheses.

iLookup = (crc32Result & 0xff) ^ buffer[i];
Matthew Jones
+5  A: 
buffer[i];  //not buffer(i)

you used parenthesis instead of brackets.

Robert Greiner
+5  A: 

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

^ buffer[i];

Eifion
+5  A: 

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

So

iLookup = (crc32Result & 0xff) ^ buffer[i];
Sean Nyman
+5  A: 

it should be

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

FlappySocks
+10  A: 

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

messenger
+1 for extra explanation.
Robert Greiner
A: 

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.

R Ubben