C#的反射和特性

class MyClass
    {
        private int id;
        private int age;
        public int number;
        public string Name { get; set; }
        public string Name2 { get; set; }
        public string Name3 { get; set; }

        public void Test1() {

        }
        public void Test2() {

        }
    }

 class Program {
        static void Main(string[] args) {
            //每一个类对应一个type对象,这个type对象存储了这个类 有哪些方法跟哪些数据 哪些成员
            //MyClass my = new MyClass();//一个类中的数据 是存储在对象中的, 但是type对象只存储类的成员
            //Type type = my.GetType();//通过对象获取这个对象所属类 的Type对象
            //Console.WriteLine(type.Name);//获取类的名字
            //Console.WriteLine(type.Namespace);//获取所在的命名空间
            //Console.WriteLine(type.Assembly);
            //FieldInfo[] array= type.GetFields();//只能获取public 字段
            //foreach (FieldInfo info in array)
            //{
            //    Console.Write(info.Name+" ");
 

猜你喜欢

转载自blog.csdn.net/qq_39646949/article/details/123080126