combine Arrays Horizontal - CSharp System

CSharp examples for System:Array Element

Description

combine Arrays Horizontal

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from w  w w . ja v  a  2 s  .  c o  m

public class Main{
        public static double[][] combineArraysHorizontal(double[] a, double[][] inputArrays)
        {
            foreach(double[] array in inputArrays)
                if (a.Length != array.Length)
                    throw new Exception("Arrays have to be the same size: " + a.Length + " != " + array.Length);

            double[][] output = new double[a.Length][];
            for(int i = 0; i < output.Length; i++)
            {
                output[i] = new double[1 + inputArrays.Length];
                output[i][0] = a[i];
                for (int b = 0; b < inputArrays.Length; b++)
                    output[i][b + 1] = inputArrays[b][i];
            }

            return output;
        }
}

Related Tutorials