Combine Arrays - CSharp System

CSharp examples for System:Array Element Add

Description

Combine Arrays

Demo Code


using System;/*from   w w w . j a v a 2  s.  c  om*/

public class Main{
        public static T[] CombineArrays<T>(params T[][] arrayList)
        {
            int combinedLength = 0;
            foreach (T[] arg in arrayList)
            {
                combinedLength += arg.Length;
            }

            T[] combinedArray = new T[combinedLength];
            int nextIndex = 0;
            foreach (T[] arg in arrayList)
            {
                Array.Copy(arg, 0, combinedArray, nextIndex, arg.Length);
                nextIndex += arg.Length;
            }

            return combinedArray;
        }
}

Related Tutorials