c# 从地址拷贝byte_从字节数组到另一个字节数组在C#中的特定位置复制字节

I have two byte arrays - array1 and array2 .

My aim is to copy the bytes from 1st array to second with respect to the start index of each array and fill the non filled bytes with a specific byte.

byte[] array1 = new byte[5]

The data is as follows: 11,22,00,33,44;

byte[] array2 = new byte[10];

I need to copy the bytes from array1 to array2. The data needs to be copied from position 3 in array2 and fill the rest of the empty positions with value ff.

ie my result in array2 would be {ff,ff,ff,11,22,00,33,44,ff,ff}

Any help would be appreciable.

Thanks in advance!

解决方案// Init array2 to 0xff

for (int i = 0; i < array2.Length; i++)

array2[i] = 0xff;

// Copy

Array.Copy(array1, 0, array2, 3, array2.Length);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值