博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# 反射
阅读量:2026 次
发布时间:2019-04-28

本文共 1271 字,大约阅读时间需要 4 分钟。

using System;using System.Reflection;namespace ConsoleApplication20{    class Program    {        static void Main(string[] args)        {            /*            string n = "grayworm";            Type t = n.GetType();            foreach (MemberInfo mi in t.GetMembers())            {                Console.WriteLine("{0}/t{1}", mi.MemberType, mi.Name);            }            */            AA aa = new AA(1,2);            Type t = aa.GetType();            foreach (MemberInfo mi in t.GetMembers())            {                Console.WriteLine("{0}/{1}", mi.MemberType, mi.Name);            }            ConstructorInfo[] ci = t.GetConstructors();    //获取类的所有构造函数            foreach (ConstructorInfo c in ci) //遍历每一个构造函数            {                ParameterInfo[] ps = c.GetParameters();    //取出每个构造函数的所有参数                foreach (ParameterInfo pi in ps)   //遍历并打印所该构造函数的所有参数                {                    Console.Write(pi.ParameterType.ToString() + " " + pi.Name + ",");                }                Console.WriteLine();            }        }    }    class AA    {        public int a { get; set; }        public AA(int a,int b)        {            this.a = a + b;        }        public static int A(int x)        {            return x + 1;        }    }}

转载地址:http://vtdaf.baihongyu.com/

你可能感兴趣的文章
[转载]History(历史)命令用法 15 例
查看>>
python的安装和版本选型
查看>>
google app api相关(商用)
查看>>
linux放音乐cd
查看>>
开源im方案之openfire
查看>>
OneNote无法同步问题
查看>>
GridView选择性导出Excel
查看>>
GridView+存储过程实现'真分页'
查看>>
2014第12周-周结
查看>>
HTML5-认识篇
查看>>
Web Service(一):Hello World
查看>>
Web Service(二):+ Web三层架构 (One Demo,More Questions)
查看>>
Web Service(三):先了解SOA
查看>>
计算机系统—CPU结构和内部工作
查看>>
也谈编译 VS 解释
查看>>
五大算法基本思想—分治,动态规划,贪心,回溯,分支界限
查看>>
五大算法思想—贪心算法
查看>>
开启 J2EE(一)—‘全明星队伍’
查看>>
开启 J2EE(二)— JDBC
查看>>
开启 J2EE(三)—Servlet
查看>>