具体什么是反射就不再多解释了,通俗一点就是可以由类型得到其相关的信息(事实上如果是方法的话我们还可以去调用)。好了先看一看几个例子: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.Globalization; namespace Reflection { class MyFather { public MyFather() { } public int FatherMethodOne() { return 1; } protected void FatherMethodTwo() { Console.WriteLine("FatherMethodTwo!"); } private void FathodMethodThree() { Console.WriteLine("FathodMethodThree!"); } } class MyTest : MyFather { private int i; private int j = 10; public int k; public MyTest() { } public MyTest(int i) { this.i = i; } public int MethodOne() { return i * j; } public static int MethodTwo() { return 10; } private void MethodThree() { Console.WriteLine("MethodThree!"); } } class Program { //static void Main(string[] args) //{ // /*反射的核心是Type类,它封装了对象的信息,是反射的入口 // * 获得Type实例有两种方式:已加载程序集的和未加载程序集的 // * 前者有三种方法: // * // */ // Type tp = Type.GetType("System.IO.Stream");//方法一:用Type类的静态方法 // Console.WriteLine(tp.ToString()); // Type tp2 = typeof(System.IO.Stream);//方法二:使用typeof // Console.WriteLine(tp2.ToString()); // string str = "cmjstudio"; // Console.WriteLine(str.GetType());//方法三:通过类型实例来获得 //} //获取信息 static void Main(string[] args) { //基本信息