2

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!

Anders
  • 12,088
  • 34
  • 98
  • 146

8 Answers8

12

Change buffer(i) to buffer[i]

John Rasch
  • 62,489
  • 19
  • 106
  • 139
10

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

messenger
  • 614
  • 5
  • 12
7

Use brackets instead of parentheses.

iLookup = (crc32Result & 0xff) ^ buffer[i];
Matthew Jones
  • 25,644
  • 17
  • 102
  • 155
5
buffer[i];  //not buffer(i)

you used parenthesis instead of brackets.

Robert Greiner
  • 29,049
  • 9
  • 65
  • 85
5

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

^ buffer[i];

Eifion
  • 5,403
  • 2
  • 27
  • 27
5

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

So

iLookup = (crc32Result & 0xff) ^ buffer[i];
Sean
  • 4,450
  • 25
  • 22
5

it should be

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

FlappySocks
  • 3,772
  • 3
  • 32
  • 33
0

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
  • 2,225
  • 16
  • 8