class Program { static void Main(string[] args) { var bc = new BaseClass(); var mc1 = new MyClass(); var mc2 = new MyClass(); BaseClass[] arrBc = new BaseClass[] { bc, mc1,mc2 }; foreach (var b in arrBc) { Type t = b.GetType(); Console.WriteLine("Object type:{0}", t.Name); FieldInfo[] fi = t.GetFields(); foreach (var f in fi) { Console.WriteLine(" Field:{0}", f.Name); } } Console.Read(); } } public class BaseClass { public int BaseField = 0; } public class MyClass:BaseClass { private string _ID; private string _name; private string _pwd; private string _email; public int MyClassField; public string ID { get { return _ID; } set { _ID = value; } } public string Name { get { return _name; } set { _name = value; } } public string Pwd { get { return _pwd; } set { _pwd = value; } } public string Email { get { return _email; } set { _email = value; } } }
以下为对上程序的图解