G
Guest
Hi There -
The code that follows does not work. I'm trying to dynamically invoke a
method that contains a params-attributed parameter. However, the array of
objects that are passed into the method are not put into an array, so the
method signature never matches the object array of parameters. Is there
another way around this without explicitly creating an array (a la new
object[] {new int[] {1, 2, 3}})?
class A
{
public static Main()
{
A a = new A();
a.GetType().GetMethod("Eval").Invoke(null, new object[] { 1, 2, 3
});
}
public static void Eval(params int[] list)
{
int x = 0;
foreach (int i in list)
{
x += i;
}
int total = x;
}
}
Thanks in advance,
Craig
The code that follows does not work. I'm trying to dynamically invoke a
method that contains a params-attributed parameter. However, the array of
objects that are passed into the method are not put into an array, so the
method signature never matches the object array of parameters. Is there
another way around this without explicitly creating an array (a la new
object[] {new int[] {1, 2, 3}})?
class A
{
public static Main()
{
A a = new A();
a.GetType().GetMethod("Eval").Invoke(null, new object[] { 1, 2, 3
});
}
public static void Eval(params int[] list)
{
int x = 0;
foreach (int i in list)
{
x += i;
}
int total = x;
}
}
Thanks in advance,
Craig