public class TwoGroup
        {
            private int _one;
            public int one
            {
                set { _one = value; }
                get { return _one; }
            }
            private int _two;
            public int two
            {
                set { _two = value; }
                get { return _two; }
            }        }如何用 for 或者 foreach 来历遍 TwoGroup 中的属性成员数。

解决方案 »

  1.   


    PropertyInfo[]  propArray = (typeof(TwoGroup)).GetProperties();
    foreach(PropertyInfo prop in propArray)
    {
       //todo
    }
      

  2.   

    object.GetType().GetProperties()foreach
      

  3.   

    Type type = typeof(TwoGroup);
    foreach (System.Reflection.PropertyInfo propertyInfo in type.GetProperties())
    {
    System.Console.WriteLine(propertyInfo.Name);
    }
      

  4.   

    PropertyInfo[] peroperties = typeof(TwoGroup).GetProperties(BindingFlags.Public | BindingFlags.Instance);
      foreach (PropertyInfo property in peroperties)
      {
      Console.Write(property.Name);
      }
     
     
      

  5.   

    PropertyInfo[] peroperties = typeof(TwoGroup).GetProperties(BindingFlags.Public | BindingFlags.Instance);
      foreach (PropertyInfo property in peroperties)
      {
      Console.Write(property.Name);
      }
      
    反射。。