Cast IEnumerable To List - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

Cast IEnumerable To List

Demo Code


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

public class Main{
        public static List<T> CastOrToList<T>(this IEnumerable<T> source)
        {/*from   w  w  w . j a  v a2 s. c o  m*/
            return source as List<T> ?? source.ToList();
        }
}

Related Tutorials