我遇到了参数数量不匹配的异常:
遇到未处理的异常:System.Reflection.TargetParameterCountException: 参数计数不匹配。
代码:
class Program
{
public static void Main()
{
ArrayList CustomerList = new ArrayList();
CustomerList.Add("Robinson");
CustomerList.Add("Pattison");
CustomerList.Add("Todd");
object[] obj = (object[])CustomerList.ToArray(typeof(object));
Assembly executingAssembly = Assembly.GetExecutingAssembly();
Type customerType = executingAssembly.GetType("LateBinding.Customer");
object customerInstance = Activator.CreateInstance(customerType);
MethodInfo method = customerType.GetMethod("printCustomerDetails");
string customerObject = (string)method.Invoke(customerInstance, obj);
Console.WriteLine("Value is : {0}", customerObject);
}
}
public class Customer
{
public string printCustomerDetails(object[] parameters)
{
string CustomerName = "";
foreach (object customer in parameters)
{
CustomerName = CustomerName + " " + customer;
}
return CustomerName.Trim();
}
}
ArrayList
的建议;P - Matías Fidemraizer