在c#中把字符串转为变量名并获取变量值的小例子(转)

public class Program

{

public string str = "spp";

public string spp = "Hello World!";

public static void Main(string[] args)

{

Program p = new Program();

Console.WriteLine(p.GetType().GetField(p.str).GetValue(p).ToString());

Console.ReadKey();

}

}

转载于:https://www.cnblogs.com/xiexiaokui/p/5143757.html

你可能感兴趣的:(在c#中把字符串转为变量名并获取变量值的小例子(转))