为什么此代码导致 shipping.Items.Count 和 combinedShipment.Items.Count 都为零?
private static InboundShipment CombineLikeIsbns(InboundShipment shipment)
{
// shipment.Items has a count of 3
var distinctIsbns = shipment.Items.Select(i => i.ISBN).Distinct().ToList();
var combinedShipment = shipment;
combinedShipment.Items = new List<InboundShipmentItem>();
// Now both combinedShipment and shipment have an empty List in the .Items property
...
return combinedShipment;
}
[编辑] 当我将 combineShipment.Items 设置为相同时,我该怎么做才能避免将 shipping.Items 设置为新列表?