例子一:已知一个类有两个属性,打印属性名的代码如下。要求屏蔽某个属性。

已知:

    class Program
    {
        static void Main(string[] args)
        {
            PropertyInfo [] info=new Test().GetType().GetProperties();
            foreach(PropertyInfo p in info)
            {
                Console.WriteLine(p.Name);
            }
            Console.ReadLine();

        }
    }

    public class Test
    {
        public string One { get; set; }
        public string Two { get; set; }

    }
}
View Code

相关文章: