我是C++開發人員,最近開始使用WPF。那麼我在我的應用程序中使用Array.Copy(),看起來像我不能完全得到所需的結果。未能在我的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[]' and 'int'
。
怎樣才能做到這一點? :)請幫忙:)
沒錯。 C#沒有瘋狂的隱式數組指針轉換來混淆每個人。 – chris
@chris:那我們怎麼才能達到它的好友? :)任何替代方法? –
我不會是要問的人。我對C#還不是很有經驗,但我喜歡它處理一些我認爲是C/C++缺陷的方式。 – chris