c# 如何将一个list集合隐式转换为另一个list集合
没转化之前:
public class ShopSpecialTimeExtParams
{
public int ShopId { get; set; }
public List<SpecialTimeExtItem> TimeExts { get; set; }
}
public class SpecialTimeExtItem
{
public string SpecialStartDate { get; set; }
public string SpecialEndDate { get; set; }
public string SpecialStartTime { get; set; }
public string SpecialEndTime { get; set; }
public int PromiseTimeChange { get; set; }
}
ShopSpecialTimeExtParams = new ShopSpecialTimeExtParams()
{
ShopId = shopSpecialTimeExt.ShopId,
TimeExts = shopSpecialTimeExt.TimeExts 无法隐式转换
},
使用 Select进行处理转换
ShopSpecialTimeExtParams = new ShopSpecialTimeExtParams()
{
ShopId = shopSpecialTimeExt.ShopId,
TimeExts = shopSpecialTimeExt.TimeExts.Select(n => new SpecialTimeExtItem()
{
SpecialStartDate = n.SpecialStartDate,
SpecialEndDate = n.SpecialEndDate,
SpecialStartTime = n.SpecialStartTime,
SpecialEndTime = n.SpecialEndTime,
PromiseTimeChange = n.PromiseTimeChange
}).ToList()
}