Groups | Blog | Home
all groups > dotnet faqs > december 2003 >

dotnet faqs : Need help with BynaryReader and SBytes


[Gauthier]
12/27/2003 8:16:07 PM
Hi,

I'm trying to populate a structure that contain sbyte[] (signed byte array)
with an instance of BinaryReader class, my problem is that I don't see
ReadSbytes(int count) method however there is a similar method for byte[]
(unsigned byte array).

So my question are:
-Is there any valid reason for the absence of the ReadSBytes method?
-What way shoud I use to populate my signed byte array easily?

Much thanks for your support

Gauthier

[Gauthier]
12/28/2003 4:26:39 AM
Anyway, I've just added theses members to a custom binaryreader class:

public sbyte[] ReadSBytes(int count)
{
return GetSBytesFromBytes(base.ReadBytes(count));
}
static sbyte[] GetSBytesFromBytes(byte[] bytes)
{
sbyte[] sbytes = new sbyte[bytes.Length];
for(int i = 0; i < sbytes.Length; i++)
{
sbytes[i] = (sbyte) bytes[i];
}
return sbytes;
}

is there a better way to achieve this?

Thanks

Gauthier


[quoted text, click to view]
| Hi,
|
| I'm trying to populate a structure that contain sbyte[] (signed byte
array)
| with an instance of BinaryReader class, my problem is that I don't see
| ReadSbytes(int count) method however there is a similar method for byte[]
| (unsigned byte array).
|
| So my question are:
| -Is there any valid reason for the absence of the ReadSBytes method?
| -What way shoud I use to populate my signed byte array easily?
|
| Much thanks for your support
|
| Gauthier
|
|

Mattias Sjögren
12/29/2003 10:47:49 PM

[quoted text, click to view]

I'd use Buffer.BlockCopy to copy the data from one array to the other.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
AddThis Social Bookmark Button