Thursday 15 April 2010

byte[] to byte[int] - C# -



byte[] to byte[int] - C# -

well, problem has been causing me problems quite time :-(

in short, have code :

byte[] code; byte[] morecodes; int x = morecodes.length; code = morecodes[x]; // error !!

i have tried method

for(int = 0; < morecodes.length; i++) { code = morecodes[i]; // error !! }

so question is, how apply/copy several bytes of code empty byte container ? byte[] code empty, want create byte contain total contents of morecodes.

an alternative thought had utilize loop & apply morecodes itself, :

for(int = 0; < morecodes.length; i++) { morecodes = morecodes[i] ; // error !! }

any ideas on how accomplish prepare problem appreciated, sense silly issue should able solve, it's defiantly 1 of can't head around.

thanks reading

right can't compile because mixing byte arrays single bytes. arrays hold bytes, makes no sense seek create array equal 1 byte.

also, @ runtime, getting error on morecodes.length.

that's because don't have "an empty byte container", don't have container @ all.

try

list<byte> morecodes = new list<byte>();

and can add together it

morecodes.add(0xaa);

and when info added, turn array:

code = morecodes.toarray();

or, if know desired length in advance, can utilize array:

byte[] morecodes = new byte[72]; // here [72] specifies size for( int = 0; < morecodes.length; ++i ) morecodes[i] = (byte)i; // here [i] accesses 1 byte within array

c# byte

No comments:

Post a Comment