C#将字节数组添加到不断增长的字节列表中

C#将字节数组添加到不断增长的字节列表中,c#,arrays,arraylist,C#,Arrays,Arraylist,如何将字节数组转换为字节列表?每当计时器滴答作响时,列表就会增长。这是我当前的代码。Visual studio不喜欢tempBuffer.Add(temp);。这给了我一个错误 List tempBuffer=新列表() 我想我解决了自己的问题。我刚刚使用了tempBuffer.AddRange(temp);我相信这将把数组添加到我的列表中 private void timer1_Tick(object sender, EventArgs e) { int by

如何将字节数组转换为字节列表?每当计时器滴答作响时,列表就会增长。这是我当前的代码。Visual studio不喜欢tempBuffer.Add(temp);。这给了我一个错误

List tempBuffer=新列表()


我想我解决了自己的问题。我刚刚使用了tempBuffer.AddRange(temp);我相信这将把数组添加到我的列表中

    private void timer1_Tick(object sender, EventArgs e)
    {

        int bytestoread = 0;

        timer1.Stop();
        try
        {
            bytestoread = serialPort1.BytesToRead;
        }
        catch(InvalidOperationException ex)
        {
            MessageBox.Show("Serial connection lost. Exception types:" + ex.ToString());
        }
        if (serialPort1.IsOpen)
        {
            if(bytestoread != 0)
            {
                byte[] temp = new byte[bytestoread];
                serialPort1.Read(temp, 0, bytestoread);
                tempBuffer.Add(temp);
           }
        }
        timer1.Start();
    }