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

   

  //源数据

   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);
            }

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