我是一名C开发人员,最近开始从事
WPF工作.好吧,我在我的应用程序中使用Array.Copy(),看起来我无法完全获得所需的结果.
我在我的C应用程序中完成了如下操作:
static const signed char version[40] = { 'A','U','D','I','E','N','C',// name 0,// reserved,firmware size 0,// board number 0,// variant,version,serial 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,8); // the first 8 bytes memloc += 16; // the 8 copied,plus 8 reserved bytes
我在我的WPF(C#)应用程序中执行了类似的操作,如下所示:
Byte[] sendBuf = new Byte[256]; char[] version = { 'A',// name '0','0',firmware size '0',// board number '0',serial '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,8); // the first 8 bytes memloc += 16;
但是它在Array.Copy中抛出了一个错误(sendBuf memloc,8);因为运算符”不能应用于’byte []’和’int’类型的操作数.
怎么能实现这个???? :) 请帮忙 :)
解决方法
for(int i = 0; i < 8; i++) { sendBuf[i+memloc] = Convert.ToSByte(version[i]); }