将一个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;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM