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



标题  
姓名  
主页
验证码 *
内容(提交失败后,可以通过“恢复上次提交”恢复刚刚提交的内容)
 
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
[使用Ctrl+Enter键可以直接提交]
 
相关链接:



<2008年6月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

导航

统计

常用链接

留言簿(3)

随笔分类(133)

随笔档案(111)

文章分类(65)

文章档案(53)

相册

收藏夹(30)

BLOG

Book store

Graphics Design

搜索

最新评论

阅读排行榜

评论排行榜