示例代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FanSheTest { class Program { static void Main(string[] args) { Dog dog = new Dog(); dog.Age = 2; dog.Name = "XiaoHei"; Console.WriteLine(dog.GetType().GetProperty("Name").GetValue(dog)); Console.WriteLine(dog.GetType().GetProperty("Age").GetValue(dog)); Console.ReadKey(); } } public class Dog { public string Name { get; set; } public int Age { get; set; } } }