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 阅读(534) 评论(0)  编辑 收藏 引用 所属分类: .NET

只有注册用户登录后才能发表评论。
<2026年11月>
日一二三四五六
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

导航

统计

常用链接

留言簿(7)

随笔分类(133)

随笔档案(111)

文章分类(65)

文章档案(53)

相册

收藏夹(30)

BLOG

Book store

Graphics Design

搜索

最新评论

阅读排行榜

评论排行榜