假设  从文本框获得一个值
   string name = txtName.text;
   然后定义了个泛型集合
  Dictionary<string,BodyCheckItem> "这里可以用name做动态变量名吗"  
= new Dictionary<string,BodyCheckItem>();

解决方案 »

  1.   

    可以。你把name放进去的时候,比如说:第一次你放进去name 第二次就放name+1 第三次就是 name+2
    name就成了  name,name1,name2.......
      

  2.   

    int   getValue(string   wl)   
      {   
      FieldInfo   fi=this.GetType().GetField("a"+wl   
      ,BindingFlags.NonPublic|BindingFlags.Instance   
      );   
      if(fi==null)   
      throw(new   Exception("cant   find   a"+wl));   
      if(fi.FieldType!=typeof(int))   
      throw(new   Exception("type   unmatched"));   
      return   (int)fi.GetValue(this);   
      }
    using   System;   
      using   System.Reflection;   
        
      namespace   XX   
      {   
      class   Class1   
      {   
      int   bc=100;   
      int   abc=1000;   
      public   int   getValue(string   wl)   
      {   
      FieldInfo   fi=this.GetType().GetField("a"+wl   
      ,BindingFlags.NonPublic|BindingFlags.Instance   
      );   
      if(fi==null)   
      throw(new   Exception("cant   find   a"+wl));   
      if(fi.FieldType!=typeof(int))   
      throw(new   Exception("type   unmatched"));   
      return   (int)fi.GetValue(this);   
      }   
      public   void   Run()   
      {   
      Console.Write(this.getValue("bc"));   
      }   
      }   
      class   XX   
      {   
      [STAThread]   
      static   void   Main(string[]   args)   
      {   
      new   Class1().Run();   
      }   
      }   
      }
      

  3.   

    可以.
    动态生成类
    参考这里:http://dotnet.chinaitlab.com/CSharp/745310.html