其实会获取字段值,其它的也应该没问题了。^_^
using System; using System.Reflection; namespace ConsoleTest { class Program { static void Main(string[] args) { Cat c = new Cat(); c.name = "mao"; c.age = 1; ShowValues(c); Console.ReadLine(); } static void ShowValues(Cat c) { Type t = c.GetType(); foreach (FieldInfo f in t.GetFields()) { Console.WriteLine(t.InvokeMember(f.Name, BindingFlags.GetField, null, c, null).ToString ()); } } } public class Cat { public int age; public string name; public string CatName { get { return name; } } } }
本文转自today4king博客园博客,原文链接:http://www.cnblogs.com/jinzhao/archive/2009/05/06/1450524.html,如需转载请自行联系原作者