Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert from string array to byte array

Tags:

c#

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.

like image 462
Evyatar Avatar asked Aug 29 '26 23:08

Evyatar


1 Answers

Try using Linq:

 string source = "1,2,3,4,5";

 byte[] result = source
   .Split(',')
   .Select(item => byte.Parse(item))
   .ToArray();
like image 136
Dmitry Bychenko Avatar answered Sep 01 '26 15:09

Dmitry Bychenko