Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将整个数组值赋给c#中的另一个变量?_C# - Fatal编程技术网

将整个数组值赋给c#中的另一个变量?

将整个数组值赋给c#中的另一个变量?,c#,C#,我有一个数组,我想把它分配给另一个数组变量。这是密码 for (int i = 0; i < length; i++) { arr1[i] = Convert.ToByte(Tag_uid.Substring(2 * i, 2), 16); } //Create an array to hold the Command Packet byte[] CommandPacket = new byte[

我有一个数组,我想把它分配给另一个数组变量。这是密码

for (int i = 0; i < length; i++)
        {
            arr1[i] = Convert.ToByte(Tag_uid.Substring(2 * i, 2), 16);
        }



        //Create an array to hold the Command Packet
        byte[] CommandPacket = new byte[9];


        CommandPacket[0] = arr1;   //ERROR: cannot convert type byte[] to byte
for(int i=0;i
如何将整个数组值分配给
commandpacket[0]

如何

for (int i = 0; i < length; i++)
{
    arr1[i] = Convert.ToByte(Tag_uid.Substring(2 * i, 2), 16);
}

byte[][] CommandPacket = new byte[9][];

CommandPacket[0] = arr1;
for(int i=0;i
不,你不能
无法将byte[]类型转换为byte
(我也不认为您的循环形成arr1是正确的)
CommandPacket[0]
是一个单字节。您希望如何为其分配字节数组?如果您希望CommandPacket(数组)包含arr1的值,为什么不跳过arr1并在循环中分配值呢?最后:是C#还是Java?你可能想使用正确的标记?@L.B,我知道我不能那样转换,所以我需要一种存储值的方法。arr1的循环是正确的,它将一堆字符串转换为字节并存储在数组中。@igrimpe这就是我要问的问题。“CommandPacket[0]”无法保存数据或arr1。顺便说一句,跳过arr1并分配有效的值。。非常感谢。对于标签,如果我没有错的话,我只使用了c#标签。。很抱歉,如果有java标记,我没有看到它。@Liban
arr1的循环是正确的
。a) 当
i
超过长度/2时,您将得到异常b)您从字符串中提取两个字符(作为子字符串),但通过
1
激活
i
,谢谢这也起到了作用。。但我想在循环内部分配“CommandPacket[]”(如上面@igrimpe所建议的)更容易,而不需要使用锯齿数组。无论如何,谢谢你的帮助。。