將一個byte[]陣列根據大小拆分為若干小byte[]陣列方法
阿新 • • 發佈:2018-11-11
/// <summary>
/// 將大陣列拆分為多個小陣列
/// </summary>
/// <param name="superbyte">需要拆分原始陣列</param>
/// <param name="size">拆分後單個數組大小</param>
/// <returns></returns>
public List<byte[]> SplitList(byte[] superbyte , int size)
{
List<byte[]> result = new List<byte[]>();
int length = superbyte.Length;
int count = length / size;
int r = length % size;
for (int i = 0; i < count; i++)
{
byte[] newbyte = new byte[size];
newbyte = superbyte.Skip(size * i).Take(size).ToArray();// SplitArray(superbyte, size*i, size * i+ size);
result.Add(newbyte);
}
if (r != 0)
{
byte[] newbyte = new byte[r];
newbyte = superbyte.Skip(length - r).Take(r).ToArray();
result.Add(newbyte);
}
return result;
}