小技巧:在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();         }     }
相關文章
相關標籤/搜索