先把对象转化成Type类型,再获取它的属性,再获取属性的值。
static void Main(string[] args) { object obj = new { Name = "小红", Age= "18!" }; Console.WriteLine("Name:\t" + obj.GetType().GetProperty("Name").GetValue(obj)); Console.WriteLine("Age:\t" + obj.GetType().GetProperty("Age").GetValue(obj)); Console.ReadKey(); }
转发于:https://www.cnblogs.com/Dumb-dog/p/14807201.html
标签:Console,读取,C#,Age,Object,GetValue,obj,属性,Name From: https://www.cnblogs.com/mtjj/p/17199293.html