Flatten List<byte[]> - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:List

Description

Flatten List<byte[]>

Demo Code


using System.Linq;
using System.Collections.Generic;
using System;// w ww.  j  a v  a  2s.  c o m

public class Main{
        public static byte[] Flatten(this List<byte[]> arrays) {
            var size = arrays.Select(e => e.Length).Sum();
            var result = new byte[size];
            var offset = 0;
            foreach (var array in arrays) {
                array.CopyTo(result, offset);
                offset += array.Length;
            }
            return result;
        }
}

Related Tutorials