首页 > Windows开发 > 详细

c# List<List<object(Id,Name)> 转换成 Dictionary<string, string>

时间:2019-09-25 20:04:14      阅读:264      评论:0      收藏:0      [点我收藏+]

   

 

  //源数据

   List<object> li = new List<object>();
            foreach (var i in list)
            {
                li.Add(new { Id = i.Id, Name = i.Name });
            }

 //需要过渡的实体

 class TruckTeam
        {
          public string Id { get; set; }
           public string Name { get; set; }
        }

//接收的字典

Dictionary<string, string> a = new Dictionary<string, string>();

  //得到数据

  var s = li.Select(p=>p).ToList();

  //循环
            foreach (var i in s)
            {
                TruckTeam d = new TruckTeam();

    //拷贝转换  
                i.CopyTo<TruckTeam>(d);
                a.Add(d.Id,d.Name);
            }

c# List<List<object(Id,Name)> 转换成 Dictionary<string, string>

原文:https://www.cnblogs.com/ruiyuan/p/11586842.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!