1
リスト内のすべてのLineSumの総計にTotalSumを設定するにはどうすればよいですか?ビューモデルの総計プロパティの値を設定する方法
これはショッピングカートで、リスト内の各商品(商品価格*数量)とショッピングカートの合計(lineSum1 + lineSum2 + lineSum3など)を計算する必要があります。
public class ViewModelShoppingCart
{
public string Title { get; set; }
[DataType(DataType.Date)]
public DateTime CreateDate { get; set; }
public List<ViewModelShoppingCartItem> ShoppingCartItems { get; set; }
public decimal TotalSum
{
set
{
// This clearly isn't working:
TotalSum = ShoppingCartItems.Sum();
}
}
}
public class ViewModelShoppingCartItem
{
public string ProductTitle { get; set; }
public decimal ProductPrice { get; set; }
public int Quantity { get; set; }
public decimal LineSum
{
set
{
LineSum = ProductPrice * Quantity;
}
}
}
これはStackOverflow noですか? 'return'で' get'する必要がありますか? – DavidG
@DavidG:もう一度見よ) –
ああ、私たちは同じトラックにいたと思うよ:) – DavidG