就像Type.GetProperties()的效果,只不过Type.GetProperties()只对系统定义的类有用,可是我想获得自定义的类的属性名称怎么办

解决方案 »

  1.   

    只不过Type.GetProperties()只对系统定义的类有用
    ------------
    谁告诉你的?哪本书上讲过...自定义的Type就不是Type吗...
      

  2.   

    那这段代码就打印不出n.Name的值
    namespace ConsoleApplication1
    {
        class MyClass
        {
            public string name;
            public int age;
        }
        class Program
        {
            static void Main(string[] args)
            {
                PropertyInfo[] propertys = System.Type.GetType("ConsoleApplication1.MyClass").GetProperties();
                foreach(PropertyInfo n in propertys)
                {
                    Console.WriteLine(n.Name);
                }
                Console.Read();
            }
            
        }
    }如果是这样就没问题:
     class Program
        {        
            static void Main(string[] args)
            {
                PropertyInfo[] propertys = System.Type.GetType("System.Collections.ArrayList").GetProperties();
                foreach(PropertyInfo n in propertys)
                {
                    Console.WriteLine(n.Name);
                }
                Console.Read();
            }        
        }
      

  3.   

    你那个Name是属性啊...那叫字段...要用GetField或GetFields...好好看看书...把基础打好再说...
      

  4.   

    你那个Name是属性啊...
    -----------
    你那个name和age是属性啊...小写,别误会了...