【问题标题】:how to convert two dimensional byte array into a single dimensional byte array如何将二维字节数组转换为一维字节数组
【发布时间】:2015-06-09 01:58:47
【问题描述】:
byte[][] s1_byte
static byte[][] ToBytes(string[] ascii)
{
    byte[][] results = ascii.AsEnumerable().Select(x => Encoding.UTF8.GetBytes(x)).ToArray();
    return results;
}

我想转换它。

如何将二维字节数组转换为一维字节数组

【问题讨论】:

  • 措辞很模糊,您打算如何将它们结合起来?一行一行?逐列?

标签: c#


【解决方案1】:

快速更改将使用SelectMany

static byte[] ToBytes(string[] ascii)
{
    // use `SelectMany`
    byte[] results = ascii.AsEnumerable().SelectMany(x => Encoding.UTF8.GetBytes(x)).ToArray();
    return results;
}

【讨论】:

  • 删除AsEnumerable,您将获得更简洁的代码。那里不需要。
猜你喜欢
  • 2015-08-23
  • 1970-01-01
  • 1970-01-01
  • 2014-06-21
  • 2013-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-02
相关资源
最近更新 更多