C#中怎么用字符串去执行相应的带参数的函数名?
比如从TextBox1.Text=getname
而getname又是个函数名
可以通过反射解决
比如:using System;
using System.Reflection;
using System.Collections.Generic;
using System.Text;
namespace Kchen
{
public class Test
{
Test()
{
}
public string test1 ()
{
return "yumen";
}
public static void test2()
{
object ha = Activator.CreateInstance(typeof(Test), true);
Test he = ha as Test;
MethodInfo method = he.GetType().GetMethod("test1");
string hahei = (string)method.Invoke(he,null);
}
}
}
但是函数遇到带参数如何解决?
getname(int a)