Creates a jagged array with elements of the same length - CSharp System

CSharp examples for System:Array Create

Description

Creates a jagged array with elements of the same length

Demo Code


using System;//from  www . jav a 2 s . co  m

public class Main{
        /// <summary>
        /// Creates a jagged array with elements of the same length
        /// </summary>
        /// <typeparam name="T">The element type of the array</typeparam>
        /// <param name="outerDim">length of the outer dimension</param>
        /// <param name="innerDim">length of the inner dimension</param>
        /// <returns></returns>
        public static T[][] CreateMatrixJagged<T>(int outerDim, int innerDim)
        {
            var result = new T[outerDim][];
            for (int i = 0; i < outerDim; i++)
                result[i] = new T[innerDim];
            return result;
        }
}

Related Tutorials