Re: convert int[] to byte[]
- From: "Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT dot.state.fl.us>
- Date: Mon, 11 Apr 2005 14:06:24 -0400
hi,
How the use of a BinaryWriter will avoid the need of a loop?
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message
news:MPG.1cc4cb985320a85c98bfa4@xxxxxxxxxxxxxxxxxxxxxxx
> 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: Jon Skeet [C# MVP]
- Re: convert int[] to byte[]
- References:
- convert int[] to byte[]
- From: Mimi
- Re: convert int[] to byte[]
- From: Jon Skeet [C# MVP]
- convert int[] to byte[]
- Prev by Date: Pixels vs. Twips
- Next by Date: WindowProc and RegisterWindowMessage
- Previous by thread: Re: convert int[] to byte[]
- Next by thread: Re: convert int[] to byte[]
- Index(es):
Relevant Pages
|