C#-----ExpandoObject动态属性
作者:互联网
using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Dynamic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { dynamic mileageObj = new ExpandoObject(); mileageObj.userName = "李斯"; mileageObj.userAge = 23; for (int i = 1; i <= 5; i++) { (mileageObj as ICollection<KeyValuePair<string, object>>).Add(new KeyValuePair<string, object>("动态属性" + i, "动态属性" + i)); } Console.WriteLine(JsonConvert.SerializeObject(mileageObj)); Console.ReadLine(); } } }
标签:mileageObj,Console,C#,System,ExpandoObject,-----,new,using 来源: https://www.cnblogs.com/deepalley/p/14689978.html