C#获取类的名字、属性名字、方法名字的方式

using System;
using System.Reflection;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Type myType = typeof(People);
            
            Console.WriteLine(myType.Name);//获取类的名字
            Console.WriteLine(myType.FullName);//获取类的全字
            Console.WriteLine(myType.BaseType.Name);//获取基类名字
            Console.WriteLine(myType.IsClass);//是否是类
            PropertyInfo[] propertyInfos = myType.GetProperties();//获取属性
            MethodInfo[] methodInfos = myType.GetMethods();//获取方法
            foreach (PropertyInfo item in propertyInfos)
            {
                Console.WriteLine(item.Name);
            }
            foreach (MethodInfo item in methodInfos)
            {
                Console.WriteLine(item.Name);
            }
        }
    }
    class People
    {
        public string Name { get; set; }
        public int Heigth { get; set; }
        public double Rich { get; set; }
    }
}

你可能感兴趣的:(学习笔记,C#,c#,开发语言)