將一個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