我写了下面的代码,但我有错误:索引超出了数组的范围。
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];
我该如何更正代码?