开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜