可否实现对类中属性值的索引访问,这样我就可以用循环实现对各属性的赋值与取值

解决方案 »

  1.   

    the only way is through reflectionusing System.Reflection;foreach (ProppertyInfo pi in YourObject.GetType().GetProperties())
    {
      object o = pi.GetValue(YourObject,null);
      object o2=....;
      pi.SetValue(YourObject, o2,null);
    }
      

  2.   

    sorry, typo:
    the only way is through reflectionusing System.Reflection;foreach (PropertyInfo pi in YourObject.GetType().GetProperties())
    {
      object o = pi.GetValue(YourObject,null);
      object o2=....;
      pi.SetValue(YourObject, o2,null);
    }