Skip to content

Instantly share code, notes, and snippets.

@richlander
Last active October 13, 2020 20:13
Show Gist options
  • Save richlander/d76b1354a34967d44bd83083e7af7c51 to your computer and use it in GitHub Desktop.
Save richlander/d76b1354a34967d44bd83083e7af7c51 to your computer and use it in GitHub Desktop.
Should rich go to the doctor
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
using System;
using static System.Console;
Person p = new ("rich", 98);
var maybeIll = p switch
{
{temperature: <97 } => true,
{temperature: >99} => true,
{Name: "rich", temperature: var temp} when temp switch
{
>97 and <99 => true,
_ => false
} => true,
{temperature: >97 and <99} => false,
_ => false
};
WriteLine($"{p.Name} should go to the doctor: {maybeIll}");
public record Person(string Name, int temperature);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment