Prepend Array - CSharp System

CSharp examples for System:Array Operation

Description

Prepend Array

Demo Code


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

public class Main{
        internal static T[] Prepend<T>(T value, T[] array)
        {
            if (array == null)
            {
                return new[] { value };
            }
            var newArray = new T[array.Length + 1];
            newArray[0] = value;
            Array.Copy(array, 0, newArray, 1, array.Length);
            return newArray;
        }
}

Related Tutorials