我想使用反射来执行我的函数(名称是GetAverage,没有参数)并且这个函数在Gold的名字中。
我使用此代码:
string MyFunction = "GetAverages";
Type type = typeof(MyGoldClass);
MethodInfo info = type.GetMethod(MyFunction);
int res = (int)info.Invoke(type,null);
res += 3;
但它不起作用,并产生实例错误,我不知道那是什么。注意 MyFunction 是 Gold Class 中的公共函数。我想在其他 C# 页面中调用和执行它。