小技巧:在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/cxmsky/p/3296568.html