将一个byte[]数组根据大小拆分为若干小byte[]数组方法


/// <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;
}

 
posted @ 2018-10-18 12:33  weirdgiant  阅读(4183)  评论(0编辑  收藏  举报