0
我寫下面的代碼,但我有錯誤:索引超出了數組的界限。c#error-Index超出數組範圍
int bytes = serialPort1.BytesToRead;
int r = 0;
byte[] byte_buffer = new byte[bytes];
serialPort1.Read(byte_buffer, 0, bytes);
int x = 0;
while ((byte_buffer[x] == 0)&(x<230400))
{
r++;
x++;
}
byte[] byte_mdfy = new byte[bytes-r];
我該如何更正代碼?
檢查以確保'x'也小於'byte_buffer.Length'? (或者更好 - 從'Read'獲得返回值...) – Ryan