F#
type Address =
{ State: String }
let computeSalesTax address salePrice =
match address with
| { State = "WA" } -> salePrice * 0.06m
| { State = "MN" } -> salePrice * 0.75m
| { State = "MI" } -> salePrice * 0.05m
| _ -> 0m
C#
class Address {
public string State { set; get; }
}
static decimal ComputeSalesTax(Address address, decimal salePrice) =>
address switch
{
{ State: "WA" } => salePrice * 0.06M,
{ State: "MN" } => salePrice * 0.75M,
{ State: "MI" } => salePrice * 0.05M,
_ => 0M
}
Top comments (2)
I love pattern matching a lot. And I love C#.
Woo, 75% sales tax.