Append item to Array - CSharp System

CSharp examples for System:Array Element Add

Description

Append item to Array

Demo Code



public class Main{
        public static T[] ArrayAdd<T>(this T[] obj, T item)
        {//from w w  w.  ja va2s  .c om
            if (obj == null)
            {
                return new T[1] { item };
            }

            T[] newArray = new T[obj.Length + 1];
            for (int i = 0; i < obj.Length; i++)
            {
                newArray[i] = obj[i];
            }
            newArray[newArray.Length - 1] = item;
            return newArray;
        }
}

Related Tutorials