While converting a Java application to C# I came through a strange and very annoying piece of code, which is crucial and works in the original version.
byte[] buf = new byte[length];
byte[] buf2 = bout.toByteArray();
System.arraycopy(buf2, 0, buf, 0, buf2.length);;
for (int i = (int) offset; i < (int) length; ++i) {
buf[i] = (byte) 255;
}
The part which is causing a casting error is the set into buf[i]
of the byte 255: while in Java it works fine, since java.lang.Byte
spans from 0 to 255, .NET System.Byte
spans from 0 to 254.
Because of this limitation, the output in the C# version of the application is that instead of 255, as expected, the buffer contains a set of 254.
Could anyone give me a viable alternative?
Thank you very much for the support.