gpt4 book ai didi

c# - 无法在我的 WPF 应用程序中使用 Array.Copy()

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:40:43 26 4
gpt4 key购买 nike

我是一名 C++ 开发人员,最近开始从事 WPF 方面的工作。好吧,我在我的应用程序中使用 Array.Copy() ,看起来我无法完全获得所需的结果。

我在我的 C++ 应用程序中做了如下操作:

static const signed char version[40] = {
'A', 'U', 'D', 'I', 'E', 'N', 'C', 'E', // name
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // reserved, firmware size
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // board number
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // variant, version, serial
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 // date code, reserved
};

unsigned char sendBuf[256] = {};
int memloc = 0;
sendBuf[memloc++] = 0;
sendBuf[memloc++] = 0;

// fill in the audience header
memcpy(sendBuf+memloc, version, 8); // the first 8 bytes
memloc += 16; // the 8 copied, plus 8 reserved bytes

我在我的 WPF (C#) 应用程序中做了类似的操作,如下所示:

Byte[] sendBuf = new Byte[256];

char[] version =
{
'A', 'U', 'D', 'I', 'E', 'N', 'C', 'E', // name
'0', '0', '0', '0', '0', '0', '0', '0' , // reserved, firmware size
'0', '0', '0', '0', '0', '0', '0', '0' , // board number
'0', '0', '0', '0', '0', '0', '0', '0' , // variant, version, serial
'0', '0', '0', '0', '0', '0', '0', '0' // date code, reserved
};

// fill in the address to write to -- 0
sendBuf[memloc++] = 0;
sendBuf[memloc++] = 0;

// fill in the audience header
Array.Copy(sendBuf + memloc, version, 8); // the first 8 bytes
memloc += 16;

但它在 Array.Copy(sendBuf + memloc, version, 8); 处抛出一个错误,因为 Operator '+' cannot be applied to operands of type 'byte[]'和“int”

如何实现???? :) 请帮忙:)

最佳答案

for(int i = 0; i < 8; i++)
{
sendBuf[i+memloc] = Convert.ToSByte(version[i]);
}

关于c# - 无法在我的 WPF 应用程序中使用 Array.Copy(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13132690/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com