【发布时间】:2012-02-18 10:28:03
【问题描述】:
我想从另一个类调用一个类中的一个方法。 问题是我事先不知道方法名称,我从外部 API 获取它..
例子:
class A
public class Whichone
{
public static string AA() { return "11"; }
public static string BB() { return "22"; }
public static string DK() { return "95"; }
public static string ZQ() { return "51"; }
..............
}
class B
public class Main
{
........
........
........
string APIValue = API.ToString();
string WhichOneValue = [CALL(APIValue)];
}
假设 APIValue 是 BB,那么 WhichOneValue 的值应该是 22。 这样做的正确语法是什么?
【问题讨论】:
-
使用reflection。