我怎样才能在运行时创建任意数组类型的实例? [英] How can I create an instance of an arbitrary Array type at runtime?

查看:83
本文介绍了我怎样才能在运行时创建任意数组类型的实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图反序列化的类型在编译时未知的数组。在运行时,我发现的类型,但我不知道如何创建一个实例。

I'm trying to deserialize an array of an type unknown at compile time. At runtime I've discovered the type, but I don't know how to create an instance.

是这样的:

Object o = Activator.CreateInstance(type);

这是不行的,因为没有参数的构造函数,阵列似乎没有任何构造函数。

which doesn't work because there is no parameterless constructor, Array doesn't seem to have any constructor.

推荐答案

使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.array.createinstance.aspx\">Array.CreateInstance.

这篇关于我怎样才能在运行时创建任意数组类型的实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆