C# aint blunt!
I'm finally getting time to dig into C# in Depth and try some stuff out. It's pleasing to see some of the terse constructs we now have.As a small example, this is great:
public decimal TotalPrice { get { return Lines.Sum(l => l.Price * l.Quantity * (IsVat ? 1.175m : 1) ); } }
Comments
-
If VAT is applied to the overall order rather than particular items, wouldn’t it make sense to move that logic outside the call to Sum?
decimal withoutVat = Lines.Sum(l => l.Price * l.Quantity); return IsVat ? 1.175m * withoutVat : withoutVat;
Of course, there could be some lines for which VAT is applied and some lines for which it isn’t (e.g. food) which changes things somewhat.
Jon
-
Good point! And, if lines were individually vat sensitive, then perhaps this is better:
Lines.Sum(l => l.Price * l.Quantity * (l.IsVat ? 1.175m : 1) );