【问题标题】:how to read data from a FileStream and add them to a queue in midwhile如何从 FileStream 读取数据并在中间将它们添加到队列中
【发布时间】:2021-08-23 09:28:23
【问题描述】:

我有一个客户如下

        TcpClient client = new TcpClient("127.0.0.1", 13000);
        var stream = client.GetStream();
        byte[] buff = new byte[1024];

        List<byte> bytequeue = new List<byte>();

        MemoryStream ms = new MemoryStream();
        int count = 0;
        do
        {
            count = stream.Read(buff, 0, 1024);
            ms.Write(buff, 0, count);
            
        } while (stream.CanRead && count > 0);

        stream.Flush();
        client.Close();

我想将刚刚在 while 循环中读取的字节添加到队列(字节列表)

【问题讨论】:

    标签: c# tcp tcpclient


    【解决方案1】:

    使用 linq 你可能可以做到这一点:

    bytequeue = bytequeue.Concat(buff.ToList());
    

    ToList 和 Concat 都是 Linq 函数,它们实际上按照它们的名字做。 我没有编写完整的测试应用程序。另请参阅

    https://www.techiedelight.com/convert-array-to-list-csharp/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-16
      • 2020-10-03
      • 2017-08-23
      • 1970-01-01
      • 2018-02-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多