Converting List<string> to byte[]
26,295
Depends on which encoding you want to use to convert the string
to a byte[]
but here's a sample for ASCII. It can be substituted for pretty much any encoding type
List<string> data = ...
byte[] dataAsBytes = data
.SelectMany(s => Text.Encoding.ASCII.GetBytes(s))
.ToArray();
Related videos on Youtube
Author by
Jon
Updated on April 13, 2020Comments
-
Jon about 4 years
How can I take a List and turn it into a byte array.
I thought there might be some clever LINQ options for it but am unsure eg/List.ForEach
-
Security Hound about 13 yearsWhats wrong with a simple for loop?
-
-
JaredPar about 13 yearsThat will give you a
List<byte[]>
but the OP asked for abyte[]