I need my code to do something like this - Somewhere in the code num
gets a value and after that i want to read from file EXACTLY as bytes is the number num
.
For example: If num is 39382 i need to read 39382 bytes and place them into byte[] buffer;
Before I had something like this:
ushort num = 0;
//.... num get some value;
byte[] buffer = bRead.ReadBytes(num);
Now I have to change it so that num
is a UInt32
, but then ReadBytes
doesn't work(because it wants int32). It's possible 'num' to exceeds int32. I fixed it like this:
byte[] buffer = new byte[num];
for (int j = 0; j < num; j++)
{
buffer[j] = bRead.ReadByte();
}
and it works but I am wondering is that the best way of doing it? Or there is another?