Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert List<byte[]> to one byte[] array

Tags:

c#

.net

How do I convert List<byte[]> in one byte[] array, or one Stream?

like image 301
user348173 Avatar asked Feb 01 '11 21:02

user348173


People also ask

How do I combine byte arrays?

The recommended solution to concatenate two or more byte arrays is using ByteArrayOutputStream . The idea is to write bytes from each of the byte arrays to the output stream, and then call toByteArray() to get the current contents of the output stream as a byte array.

How do you reverse Bytearray?

you can use the linq method: MyBytes. Reverse() as well as the Array. Reverse() method.

What is byte array example?

A byte is 8 bits (binary data). A byte array is an array of bytes (tautology FTW!). You could use a byte array to store a collection of binary data, for example, the contents of a file. The downside to this is that the entire file contents must be loaded into memory.

What is byte and byte array?

bytes is an immutable version of bytearray – it has the same non-mutating methods and the same indexing and slicing behavior. Syntax: bytes([source[, encoding[, errors]]]) bytearray() function : Return a new array of bytes. The bytearray type is a mutable sequence of integers in the range 0 <= x < 256.


1 Answers

SelectMany should do the trick:

var listOfArrays = new List<byte[]>();

byte[] array = listOfArrays
                .SelectMany(a => a)
                .ToArray();
like image 130
Peter Lillevold Avatar answered Oct 06 '22 00:10

Peter Lillevold