【发布时间】:2018-02-24 11:37:31
【问题描述】:
我收到参数计数不匹配异常:
获取未处理的异常: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();
}
}
【问题讨论】: