Why does Stream.ReadByte return int?
I spent some time researching the namespace System.IO
and after that I found an interesting place for me. Stream
the class contains a method named ReadByte and the definition is as follows:
public virtual int ReadByte()
So actually my question is, why is the method called ReadByte
and returns int
? What is the purpose of the naming?
source to share
ReadByte
returns
An unsigned byte is passed in
Int32
or -1 if at the end of the stream.
This approach (of particular importance, not clashing with any possible meaning byte
) leads to the use of an integral type that "expands" byte
.
In principle, types like short
will work, but it's much more natural and conditional to use int
.
source to share