Created
January 21, 2026 18:59
-
-
Save karenpayneoregon/f0f5197fe04bc3b8b71754f5946e4abd to your computer and use it in GitHub Desktop.
Logical patterns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | |
| }; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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