Compile error help byte array

  • Thread starter Thread starter AMP
  • Start date Start date
A

AMP

Hello,
I have the following code:
background:
const int MAX_DATA_BYTES=250;
byte[] blkin =new byte[MAX_DATA_BYTES]; /* Receive buffer */

and I use it in the following:
memmove(blkout[1], blkout[0], len);

but i get the following error:
Cannot apply indexing with [] to an expression of type 'byte'

What am i doing wrong?
Thanks
mike
 
Mike,

You are showing the declaration for the blkin variable, but your call on
the indexer is for the blkout variable. I would take a look at that.

Hope this helps.
 
Let me rewrite this:
Hello,
I have the following code:
background:
const int MAX_DATA_BYTES=250;
byte[] blkout =new byte[MAX_DATA_BYTES]; /* Receive buffer */

and I use it in the following:
ARRAY.COPY(blkout[1], blkout[0], len);

but i get the following error:
Cannot apply indexing with [] to an expression of type 'byte'
 
Take a look at the Buffer.BlockCopy method for this.

Willy.

| Let me rewrite this:
| Hello,
| I have the following code:
| background:
| const int MAX_DATA_BYTES=250;
| byte[] blkout =new byte[MAX_DATA_BYTES]; /* Receive buffer */
|
| and I use it in the following:
| ARRAY.COPY(blkout[1], blkout[0], len);
|
| but i get the following error:
| Cannot apply indexing with [] to an expression of type 'byte'
|
 
| Still not getting anywhere.
| I need some help.Please
| Thanks
| Mike
|

What problem do you have using BlockCopy? Please post what you have done so
far.

Here's a usage sample:
byte[] arr1 = {1, 2, 3, 4, 5};
byte[] arr2 = {10, 11, 12, 13, 14, 15};
// copy 5 bytes from arr1 starting at offset 0 to arr2 starting at offset 1
Buffer.BlockCopy( arr1, 0, arr2, 1, 5);
// result: arr2 = 10, 1, 2, 3, 4, 5

Willy.
 
Let me rewrite this:
Hello,
I have the following code:
background:
const int MAX_DATA_BYTES=250;
byte[] blkout =new byte[MAX_DATA_BYTES]; /* Receive buffer */

and I use it in the following:
ARRAY.COPY(blkout[1], blkout[0], len);

Array.Copy has a different parameter set. Assuming the original C code
was:

memmove(blkout + 1, blkout, len);

or:

memmove(&blkout[1], &blkout[0], len);

then try this:

Array.Copy(blkout, 0, blkout, 1, len);

Where blkout[0] is the source and blkout[1] is the destination.
 
Yes the original code was:
memmove(&blkout[1], &blkout[0], len);

so why doesnt my code work????????????

const int MAX_DATA_BYTES=250;
byte[] blkout=new byte[MAX_DATA_BYTES]; /* Transmit buffer */
Array.Copy(blkout,1, blkout,0, len);

what i'm getting now is:
Error 10 Argument '1': cannot convert from 'byte' to
'System.Array' M:\Rocket-CSharp\Rocket\Rocket\Form1.cs 466 20 Rocket
And
Error 11 Argument '3': cannot convert from 'byte' to
'System.Array' M:\Rocket-CSharp\Rocket\Rocket\Form1.cs 466 30 Rocket

And the next line in the program is:
blkout[0]= 0xFF;
and i get the error:

Error 12 Cannot apply indexing with [] to an expression of type
'byte' M:\Rocket-CSharp\Rocket\Rocket\Form1.cs 467 9 Rocket




I dont get it.............

Thanks Again
Mike





Rudy said:
Let me rewrite this:
Hello,
I have the following code:
background:
const int MAX_DATA_BYTES=250;
byte[] blkout =new byte[MAX_DATA_BYTES]; /* Receive buffer */

and I use it in the following:
ARRAY.COPY(blkout[1], blkout[0], len);

Array.Copy has a different parameter set. Assuming the original C code
was:

memmove(blkout + 1, blkout, len);

or:

memmove(&blkout[1], &blkout[0], len);

then try this:

Array.Copy(blkout, 0, blkout, 1, len);

Where blkout[0] is the source and blkout[1] is the destination.

--
Rudy Velthuis http://rvelthuis.de/

"If you're sick and tired of the politics of cynicism and polls
and principles, come and join this campaign." -- George W. Bush
 
AMP said:
Yes the original code was:
memmove(&blkout[1], &blkout[0], len);

so why doesnt my code work????????????

const int MAX_DATA_BYTES=250;
byte[] blkout=new byte[MAX_DATA_BYTES]; /* Transmit buffer */
Array.Copy(blkout,1, blkout,0, len);

The above code compiles fine. The problem was when you were using

blkout[1] or blkout[0], which each evaluate to a byte value, not a byte
array.
 
I managed to fix that one,(Many Thanks) but I have one that looks like
this:
memcpy(&dataOut[4], blkout, len)

The "blkout" has no index.
Any Suggestions?


AMP said:
Yes the original code was:
memmove(&blkout[1], &blkout[0], len);

so why doesnt my code work????????????

const int MAX_DATA_BYTES=250;
byte[] blkout=new byte[MAX_DATA_BYTES]; /* Transmit buffer */
Array.Copy(blkout,1, blkout,0, len);

The above code compiles fine. The problem was when you were using

blkout[1] or blkout[0], which each evaluate to a byte value, not a byte
array.
 
AMP said:
I managed to fix that one,(Many Thanks) but I have one that looks like
this:
memcpy(&dataOut[4], blkout, len)

The "blkout" has no index.
Any Suggestions?

That's basically

Array.Copy (dataOut, 4, blkout, 0, len);

(or possibly the other way round - I can't remember which way round the
arguments go in memcpy).

Jon
 
Jon said:
AMP said:
I managed to fix that one,(Many Thanks) but I have one that looks like
this:
memcpy(&dataOut[4], blkout, len)

The "blkout" has no index.
Any Suggestions?

That's basically

Array.Copy (dataOut, 4, blkout, 0, len);

(or possibly the other way round - I can't remember which way round the
arguments go in memcpy).

memcpy is <- !

Arne
 
Back
Top