Create a new array by appending the given elements. - CSharp System

CSharp examples for System:Array Element Add

Description

Create a new array by appending the given elements.

Demo Code

// Permission is hereby granted, free of charge, to any person obtaining a copy
using System;/*from   www .j  av  a  2  s.  co  m*/

public class Main{
    /// <summary>
      ///   Create a new array by appending the given elements.
      /// </summary>
      public static T[] Append<T> (T[] array, T element1, T element2)
      {
         T[] result = new T[array.Length + 2];
         Array.Copy (array, result, array.Length);
         result [array.Length] = element1;
         result [array.Length + 1] = element2;
         return result;
      }
    /// <summary>
      ///   Create a new array by appending the given element.
      /// </summary>
      public static T[] Append<T> (T[] array, T element)
      {
         T[] result = new T[array.Length + 1];
         Array.Copy (array, result, array.Length);
         result [array.Length] = element;
         return result;
      }
}

Related Tutorials