Add one element to the sequence - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

Add one element to the sequence

Demo Code


using System.Linq;
using System.Collections.Generic;

public class Main{
        /// <summary>
        /// Concats one element to the sequence
        /// </summary>
        /// <typeparam name="T">Type of the sequence</typeparam>
        /// <param name="sequence">Sequence to use</param>
        /// <param name="element">Element to concat</param>
        /// <returns>A new sequence that has the concatenation of sequence@pre + element</returns>
        public static IEnumerable<T> Concat<T>(this IEnumerable<T> sequence, T element)
        {//w ww .j  a  va 2s.  c  o  m
            return sequence.Concat(new[] { element });
        }
}

Related Tutorials