那这段代码就打印不出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();
}
}