chu*_*h97 3 c# linq generics dictionary
我有一个List<CustomObject>
有3个属性A,B,C,我需要的是将这个List转换为一个字典,所以结果看起来像
Dictionary<string,object>
(Property name) A = Value of A
(Property name) B = Value of B
(Property name) C = Value of C
Run Code Online (Sandbox Code Playgroud)
请建议......
CustomObject instance = new CustomObject();
var dict = instance.GetType().GetProperties()
.ToDictionary(p => p.Name, p => p.GetValue(instance, null));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1422 次 |
| 最近记录: |