Create List from IEnumerable - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

Create List from IEnumerable

Demo Code


using System.Collections.Generic;
using System.Collections;
using System;/*ww w .j a  va  2s.co m*/

public class Main{
        public static IList CreateList(IEnumerable collection)
        {
            ArrayList ret = new ArrayList();
            if (collection != null)
            {
                foreach (object o in collection)
                {
                    ret.Add(o);
                }
            }
            return ret;
        }

        public static List<T> CreateList<T>(IEnumerable collection)
        {
            List<T> ret = new List<T>();
            if (collection != null)
            {
                foreach (object o in collection)
                {
                    ret.Add((T)o);
                }
            }
            return ret;
        }
}

Related Tutorials