Re: casting Object to byte array



glenn <ghan***@xxxxxxxxxxxxxxxxxx> wrote:
> Nevermind, I think I figured it out, here is what I did so anyone can
> correct me if I am going to find a problem with this later on...
>
> Byte [] b = new byte[1023];
> b = (byte [])myobj;
>
> The problem was I was not adding the square brackets in my casting and was
> getting errors.

That's fine, except you're creating a new byte array for no reason -
just generating garbage.

Just use:

byte[] b = (byte[]) myobj;

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.