ITeye博客

基于泛型的对象实例构造方法

carver · 2010-12-16 10:23 · .NET · 编程语言 · Markdown

如何创建泛型空对象实例:

default(T)

 

如何创建泛型对象实例:

Activator.CreateInstance(typeof(T))

 

如何创建动态泛型对象实例:

Type listType = typeof(List<>).MakeGenericType(new Type[] { type });
IList listObjs = Activator.CreateInstance(listType) as IList;

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。