Binding type(s) to generic type

Sometimes we need to bind the type to a generic type at runtime. In this case, we can:

Type genericListType = typeof(List<>).MakeGenericType(new Type[] { typeof(string) });
object o = Activator.CreateInstance(genericListType);

Note: List<> here is just a sample, use your own generic type instead.

posted on 2008-01-01 08:19 毒菇求Buy 阅读(397) 评论(0)  编辑 收藏 引用 所属分类: .NET

只有注册用户登录后才能发表评论。
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿(7)

随笔分类(133)

随笔档案(111)

文章分类(65)

文章档案(53)

相册

收藏夹(30)

BLOG

Book store

Graphics Design

搜索

最新评论

阅读排行榜

评论排行榜