Re: convert int[] to byte[]
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Mon, 11 Apr 2005 19:00:24 +0100
Mimi <Mimi@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> Is there a way to convert int[] to byte[] easily?
>
> I want to write my int[] indexTbl to a MemoryStream but the MemoryStream
> class only accepts byte[] buffer. I have more than one int[] indexTbl to
> write to the stream so it would be nice if I could just write the whole int[]
> as a block and then read it back later when needed.
>
> I thought the Buffer class might be handy here but it seems to be best for
> converting byte[] to int[] with Block Copy.
>
> Any suggestions here. I am new to C# and wanted to avoid a for-loop and
> convert each int to a byte and then write to the stream one by one.
I'd suggest you use a BinaryWriter, assuming you want to convert each
int to four bytes. If you need to convert each int to *one* byte,
you'll need to loop through.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: convert int[] to byte[]
- From: Ignacio Machin \( .NET/ C# MVP \)
- Re: convert int[] to byte[]
- References:
- convert int[] to byte[]
- From: Mimi
- convert int[] to byte[]
- Prev by Date: Re: convert int[] to byte[]
- Next by Date: Passing parameters by reference
- Previous by thread: Re: convert int[] to byte[]
- Next by thread: Re: convert int[] to byte[]
- Index(es):
Relevant Pages
|