【发布时间】:2010-08-05 21:46:14
【问题描述】:
我不知道怎么做:
object x = new Int32[7];
Type t = x.GetType();
// now forget about x, and just use t from here.
// attempt1
object y1 = Activator.CreateInstance(t); // fails with exception
// attempt2
object y2 = Array.CreateInstance(t, 7); // creates an array of type Int32[][] ! wrong
秘诀是什么?如果我能得到数组元素的类型,我可以让第二个工作,但我也没有弄清楚那个。
【问题讨论】:
-
你让我在“秘密酱汁”。 =)
标签: c# arrays reflection constructor