开发者

Create List<T> using GetType()

开发者 https://www.devze.com 2023-01-11 05:00 出处:网络
Is it possible to create a List or IEnumerable using GetType(). // If T is Type of Contact I want to Return List<Contact>

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));
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消