Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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#_Arrays_String_Byte - Fatal编程技术网

C#字节数组到字符串数组

C#字节数组到字符串数组,c#,arrays,string,byte,C#,Arrays,String,Byte,我想将数组的字符串转换为字节数组,反之亦然 例如 现在要将其重新转换为 string [] originalArr= ??? from Byte[] 我试过了 strArr.Select(innerArray => Encoding.UTF8.GetString(innerArray)).ToList(); 但不工作简单地说: string[] strings = new string[] { "1","2","3" }; byte[] bytes = strings.Select(b

我想将数组的字符串转换为字节数组,反之亦然

例如

现在要将其重新转换为

string [] originalArr= ??? from Byte[]
我试过了

strArr.Select(innerArray => Encoding.UTF8.GetString(innerArray)).ToList();
但不工作

简单地说:

string[] strings = new string[] { "1","2","3" };
byte[] bytes = strings.Select(byte.Parse).ToArray();
strings = bytes.Select(byteValue => byteValue.ToString()).ToArray();
警告:
字节。如果字符串无法转换为字节,则Parse
将引发运行时异常,例如,它不是一个大于255的数字。可能需要额外的检查才能正确执行。签出
byte.TryParse



这只是其中一种方法。您还可能发现
Convert
类非常有用。它有许多将值转换为不同类型的静态方法,包括
convert.ToByte(…)
convert.ToString(…)
。更多详情请参见。

您所说的
不工作是什么意思,这不是重复您所指的问题。这不是真正的重复-OP想知道如何将字符串数组转换为字节数组,然后将字节数组转换回匹配的字符串数组。在此行获取错误byte[]bytes=strings.Select(byte.Parse).ToArray();如果我的字符串类似于{“ProductCode”:“PP211766”,“IsItem”:“True”,“IsBPA”:“True”},则输入字符串的格式不正确
string[] strings = new string[] { "1","2","3" };
byte[] bytes = strings.Select(byte.Parse).ToArray();
strings = bytes.Select(byteValue => byteValue.ToString()).ToArray();