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

本文介绍了一种将大数组拆分成多个指定大小的小数组的方法。通过使用C#语言实现的SplitList函数,可以有效地处理数组拆分任务。此方法首先确定原始数组的长度,并计算出每个小数组应该包含的元素数量,最后通过循环遍历完成拆分。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

///

/// 将大数组拆分为多个小数组

///

/// 需要拆分原始数组

/// 拆分后单个数组大小

///

public List SplitList(byte[] superbyte , int size)

{

List result = new List();

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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值