分配字节数组时出现奇怪的错误

Ahm*_*mia -1 c# bytearray

byte[] frame_to_send= new byte[6];
// code  

frame_to_send = { 0x68, 0x04, 0x83, 0x00, 0x00, 0x00}; `//Array edit`
Run Code Online (Sandbox Code Playgroud)

错误:

无效的表达式术语'{'
; 预期

Ren*_*ogt 7

您只能在构建时初始化时执行此操作:

byte[] frame_to_send = { 0x68, 0x04, 0x83, 0x00, 0x00, 0x00};
Run Code Online (Sandbox Code Playgroud)

以后任何时候你都可以这样做:

frame_to_send = new byte[]{ 0x68, 0x04, 0x83, 0x00, 0x00, 0x00};
Run Code Online (Sandbox Code Playgroud)

请注意,在您首先创建的代码中,创建一个所有值都设置为0的字节数组,然后(尝试)创建一个新数组,完全丢弃以前创建的数组.所以你的初始任务完全是多余的.