Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个对象列表(主要是 int、string、double)
我想将该列表中的项目转换为对象的属性。
结果应如下所示: MyObject.ItemOfList1 , MyObject.ItemOfList2
我应该如何实施?
你可以试试这样的 -
var listobj = new List<object>() { 1, 2, "3", "4", 1.2 }; var x = new ExpandoObject() as IDictionary<string, Object>; foreach (var obj in listobj) { //Add a property dynamically - property name and value x.Add(obj.ToString(), obj.ToString()); }