【发布时间】:2010-07-09 07:58:40
【问题描述】:
我有一个字节数组:
byte[] bytes; // many elements
我需要将它分成 X 元素的字节数组的子序列。例如,x = 4。
如果 bytes.Length 不乘以 X,则将 0 添加到最后一个子序列数组,因此 所有子序列的长度必须为 X。
Linq 可用。
PS:我的尝试
static void Main(string[] args)
{
List<byte> bytes = new List<byte>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
int c = bytes.Count / 4;
for (int i = 0; i <= c; i+=4)
{
int diff = bytes.Count - 4;
if (diff < 0)
{
}
else
{
List<byte> b = bytes.GetRange(i, 4);
}
}
Console.ReadKey();
}
【问题讨论】:
标签: c#