其实会获取字段值,其它的也应该没问题了。^_^

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; }
        }
    }
}

相关文章:

  • 2022-12-23
  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案