Inserts the specified at the beginning of the list (in order) and returns the mutated list. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:List

Description

Inserts the specified at the beginning of the list (in order) and returns the mutated list.

Demo Code

// BDHero is free software: you can redistribute it and/or modify
using System.Collections.Generic;
using System;/*from   w  ww.  ja  va2  s  . c  o  m*/

public class Main{
        /// <summary>
        /// Inserts the specified <paramref name="items"/> at the beginning of the list (in order) and returns the mutated list.
        /// </summary>
        /// <param name="list"></param>
        /// <param name="items"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static IList<T> Prepend<T>(this IList<T> list, params T[] items)
        {
            for (var i = items.Length; i >= 0; --i)
            {
                list.Insert(0, items[i]);
            }
            return list;
        }
}

Related Tutorials