我有兩個模型類:投對象的名單到另一名單
public class SalesItem
{
public string ProductName { get; set; }
public double UnitPrice { get; set; }
public int Quantity { get; set; }
}
public class ProductItem : INotifyPropertyChanged
{
public string ProductName { get; set; }
public double UnitPrice { get; set; }
}
我有SalesItem,List<ProductItem> products
的名單,我怎麼能轉換爲List<SalesItem> sales
EDITED
List<ProductItem> salesList = new List<ProductItem>();
List<SalesItem> salesItem = salesList.Cast<SalesItem>();
錯誤:
Connot implicitly convert type 'System.Collections.Generic.IEnumerable<Model.SalesItem>' to 'System.Collections.Generic.List<Model.SalesItem>'. An explicit conversion exists (are you missing a cast?
如何填補銷售項目的數量 –
是類'ProductItem'和'SalesItem'相關(例如從另一個繼承了?)如果是,如何? – sinelaw