FileStream.ReadByte: Byte is never a negative number?

From msdn :

FileSystem.ReadByte
Byte transferred to Int32 or -1 if end of stream is reached.

So -1 is basically a "magical meaning." Does this mean that bytes returned from streams are never negative? If not, why not?

+6
source share
4 answers

In C #, a byte values ​​are a number from 0 to 255, so the byte is never negative.

The sbyte data sbyte is a signed byte, so it has a value from -128 to 127.

(In some other languages, such as Java, the byte data type is signed.)

+10
source

Since bytes are not negative, they are numbers in the value 0-255.

+4
source

byte cannot be negative, can it? It is equal to 0 ... 255.

+4
source

FileStream.ReadByte () returns the byte value to the Int32 value, it returns -1 only if the end of the stream is reached.

+2
source

Source: https://habr.com/ru/post/890578/


All Articles