Skip to content

Instantly share code, notes, and snippets.

@karenpayneoregon
Created January 21, 2026 18:59
Show Gist options
  • Select an option

  • Save karenpayneoregon/f0f5197fe04bc3b8b71754f5946e4abd to your computer and use it in GitHub Desktop.

Select an option

Save karenpayneoregon/f0f5197fe04bc3b8b71754f5946e4abd to your computer and use it in GitHub Desktop.
Logical patterns
public static class LogicalPatterns
{
public static string ClassifyTemperature(this double temp) => temp switch
{
< 0 => "Bitterly cold",
>= 0 and < 20 => "Chilly",
>= 20 and < 30 => "Comfortably warm",
>= 30 and not 100 => "Uncomfortably hot",
100 => "At the boiling point",
_ => "Dangerously extreme"
};
}
internal partial class Program
{
static void Main(string[] args)
{
List<double> temperatures = [15.0, 25.0, 30, 35, 45, 100, 102];
foreach (var temperature in temperatures)
{
Console.WriteLine($"{temperature, -4} => {temperature.ClassifyTemperature()}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment