I am using reflection to construct a class object which accepts an int as constructor parameter. I am using ConstructorInfo.Invoke to create the class. Can any one please tell me how can I pass a parameter to the constructor? I am trying the following method without luck
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);
I get the following error:
Argument 1: cannot convert from ‘int[]’ to ‘object[]’
The signuature of
Invokeexpectsobject[]. So giveobject[]to it.