是否可以使用GetType()创建List或IEnumerable。
// If T is Type of Contact I want to Return List<Contact>
Test(typeof(Contact));//return List<Type>
public static IEnumerable<T> Test<T>(T t)
{
return new List<T>(); //return List<Type>
}
答案 0 :(得分:9)
public static IList GetList(Type type)
{
return (IList) Activator.CreateInstance(typeof(List<>).MakeGenericType(type));
}