我正在制作一个控制台应用程序,它将从字符串调用方法,现在这部分没问题,但是当涉及到参数时,我需要一些帮助
这是代码,这是来自static void main(String[]args)
//Gets the variable for the void/Method
string void_name = Console.ReadLine();
//Making the type in this case its 'Program'
Type type_ = typeof(Program);
//Making the route with the string 'void_name'
MethodInfo method_ = type_.GetMethod(void_name);
//Getting optional parameters
Object[] obj = new Object[] { "" };
foreach (ParameterInfo _parameterinfo in method_.GetParameters())
{
obj[0] = Console.ReadLine();
}
foreach (string obj_string in obj)
{
Console.WriteLine(obj_string);
}
//Calling the functions
method_.Invoke(type_, obj); <-- this is were i get the exception
}
catch (Exception exception_loop)
{
Console.WriteLine(exception_loop.Message);
Console.Clear();
}
}
}
public void helloworld(string something_)
{
Console.WriteLine("\tHeisann: " + something_);
}