I'm using C#.
I have a string array as follow: "1,2,3,4,5,..."
I'm trying to convert the string array to byte array as follow []{1,2,3,4,5,...}
What is the best way to do that?
Thanks.
I'm using C#.
I have a string array as follow: "1,2,3,4,5,..."
I'm trying to convert the string array to byte array as follow []{1,2,3,4,5,...}
What is the best way to do that?
Thanks.
byte[] byteArray = str.Select(s => Convert.ToByte(s, 16)).ToArray();
Str represent string[]. If you have string you should string[] str = string.Split(',');
s is type char. I get the following error: Argument 2: cannot convert from 'int' to 'System.IFormatProvider' In addition, this will include the commas as arguments.string and not a real string[] to begin with. The accepted answer seems to support this assumption. I agree that your answer is valid given that str is really a string[].