Create List<T> using GetType()
Is it possible to create a List or IEnumerable using GetType().
// If T is Type of Contact I want to Return List<Contact>
Test(typeof(Contact));//return List<Type>
public static IEnumerable<T> Test<T&开发者_StackOverflowgt;(T t)
{
return new List<T>(); //return List<Type>
}
public static IList GetList(Type type)
{
return (IList) Activator.CreateInstance(typeof(List<>).MakeGenericType(type));
}
精彩评论