Append values to the current array. - CSharp System

CSharp examples for System:Array Element Add

Description

Append values to the current array.

Demo Code

//     Copyright (c) Microsoft Corporation.  All rights reserved.
using System.Globalization;
using System;//from  w w w.  j  ava 2s  .  c o m

public class Main{
        /// <summary>
        /// Append values to the current array.
        /// </summary>
        /// <param name="array">Array to be appended.</param>
        /// <param name="items">Items to append.</param>
        /// <returns>Append result array.</returns>
        /// <typeparam name="T">Type of elements.</typeparam>
        public static T[] Append<T>(this T[] array, params T[] items)
        {
            T[] result = new T[array.Length + items.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = array[i];
            }

            for (int i = 0; i < items.Length; i++)
            {
                result[array.Length + i] = items[i];
            }

            return result;
        }
}

Related Tutorials