N Copies element in IList - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IList

Description

N Copies element in IList

Demo Code


using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Collections;

public class Main{
    public static IList<T> NCopies<T> (int n, T elem)
      {// w w  w  . j a  v  a 2 s .c o m
         List<T> list = new List<T> (n);
         while (n-- > 0) {
            list.Add (elem);
         }
         return list;
      }
}

Related Tutorials