Call one function from another
-
Hi, How can i call a function from another when i only have the name of the function in a string parameter. I want to call the second function with the designated parameters and get the return value.
public double F2(string param1, int param2) { } public void F1(string FunctionName) { //... // here i want to call F2 using FunctionName parameter, set the F2's parameters and get the return value }
Please help :)Do your best to be the best
-
Hi, How can i call a function from another when i only have the name of the function in a string parameter. I want to call the second function with the designated parameters and get the return value.
public double F2(string param1, int param2) { } public void F1(string FunctionName) { //... // here i want to call F2 using FunctionName parameter, set the F2's parameters and get the return value }
Please help :)Do your best to be the best
double res;
res = F2("",0);or
F2("",0);
-
Hi, How can i call a function from another when i only have the name of the function in a string parameter. I want to call the second function with the designated parameters and get the return value.
public double F2(string param1, int param2) { } public void F1(string FunctionName) { //... // here i want to call F2 using FunctionName parameter, set the F2's parameters and get the return value }
Please help :)Do your best to be the best
You need to use Reflection here. The following code is not complete but I think it will help you. using System.Reflection; ..... public void CallMethod(string methodName) { MethodInfo methodInfo = this.GetType().GetMethod(methodName); if (methodInfo == null) { throw new MissingMethodException(this.GetType().Name,methodName); } methodInfo.Invoke(this, new object[] { "Param1", 50 }); } public void MethodToBeCalled(string param1, int v) { Console.WriteLine(param1); Console.WriteLine(v); }
-
Hi, How can i call a function from another when i only have the name of the function in a string parameter. I want to call the second function with the designated parameters and get the return value.
public double F2(string param1, int param2) { } public void F1(string FunctionName) { //... // here i want to call F2 using FunctionName parameter, set the F2's parameters and get the return value }
Please help :)Do your best to be the best