Copy IEnumerable to List - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

Copy IEnumerable to List

Demo Code


using System.Collections;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*  w w  w .  j a v  a 2  s .  co m*/

public class Main{
        public static List<T> Copy<T>(this IEnumerable source)
            where T : class,new()
        {
            List<T> lstT = new List<T>();
            IEnumerator enumerator = source.GetEnumerator();
            while (enumerator.MoveNext())
            {
                lstT.Add(enumerator.Current.Copy<T>());
            }
            return lstT;
        }
}

Related Tutorials