日期:2014-05-17  浏览次数:20925 次

已知一个type类型,如何获得它的的数组形式的type
在做xml序列化时,通过参数得到一个type,如何得到它的数组类型的Type实例
void ser(Type type)
{
// 通过type获得等价于下面的数据
//var t2 = typeof(xxx[])
}

...
ser(typeof(xxx));

基础 反射

------解决方案--------------------

var t2 = type.MakeArrayType();

------解决方案--------------------
引用:

var t2 = type.MakeArrayType();

赞!
------解决方案--------------------
//返回一维数组的TYpe实例
Type tt =  typeof(Example).MakeArrayType();

//返回二维数组的TYpe实例
Type tt = typeof(Example).MakeArrayType(2);
------解决方案--------------------
例如可以写 
string[10] arr = Array.CreateInstance(typeof(string),10);