I spent some time on research System.IO namespace and after that I've found some interesting place for me. Stream class contains method with name ReadByte and definition like that:
public virtual int ReadByte()
So actually my question is why method called ReadByte and returns int?
What is the purpose of naming like that?
ReadByte returns
The unsigned byte cast to an
Int32, or -1 if at the end of the stream.
Such approach (having a special value which does not collide with any possible byte value) leads to use of a an integral type which "extends" byte.
In principle, types like short would work as well, but it is much more natural and conventional to use int.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With