0
我正在使用反射來構造一個類對象,它接受作爲構造函數參數的int
。我正在使用ConstructorInfo.Invoke
來創建課程。任何人都可以告訴我如何將一個參數傳遞給構造函數?我想下面的方法沒有運氣將值傳遞給ConstructorInfo.Invoke
Assembly ass = Assembly.GetExecutingAssembly();
Type typa = ass.GetType("Abc");
Type[] types = new Type[1];
types[0] = typeof(int);
ConstructorInfo csInfo =typa.GetConstructor(types);
int[] obj = {10};
csInfo.Invoke(obj);
我得到以下錯誤:
Argument 1: cannot convert from 'int[]' to 'object[]'