为什么 SerialPort 的 ReadByte 方法 Return 是 Int 而不是 Byte?
Why Does SerialPort's ReadByte Method Return an Int instead of a Byte?
感觉不只是 return 个字节是一个奇怪的选择。这有充分的理由吗?另外,由于这不是一个字节,我可以将它转换为一个字节来获取数据吗?
因为它 needs to return -1 在流结束的情况下:
The byte, cast to an Int32, or -1 if the end of the stream has been read.
他们本可以使用更小的类型,例如 short
/int16
。
感觉不只是 return 个字节是一个奇怪的选择。这有充分的理由吗?另外,由于这不是一个字节,我可以将它转换为一个字节来获取数据吗?
因为它 needs to return -1 在流结束的情况下:
The byte, cast to an Int32, or -1 if the end of the stream has been read.
他们本可以使用更小的类型,例如 short
/int16
。