Csharp 9 pattern matching

CSharp · Console

/Program.cs

using System;

var product = new Product()
{
    Name = "product",
    Weight = 40
};

var deliveryPrice = product.Weight switch
{
    < 30 => 0,
    >= 30 and < 50 => 20,
    >= 50 => 100
};

Console.WriteLine(deliveryPrice);


class Product
{
    public string Name { get; set; }

    public decimal Weight { get; set; }
}
;