MemoryStream: why convert to byte after readByte

前端 未结 3 724
眼角桃花
眼角桃花 2021-01-17 11:46

In this example from MS, you\'ll notice that after we read a byte from memory stream, it goes into an int which must then be converted to byte. It stikes me as strange that

3条回答
  •  无人及你
    2021-01-17 11:57

    This is not specific to Memory stream, rather it is because of the design of base class "Stream" and the reason for that is

    Return value:

    The unsigned byte cast to an Int32, or -1 if at the end of the stream.

    -1 cannot be represented using unsigned byte

提交回复
热议问题