What's New in C# 9.0
docs.microsoft.com
docs.microsoft.com
private List<WeatherObservation> _observations = new();
This is something I've long wondered why I couldn't do and I'm glad I'll be able to in C# 9.> Top-level statements enable a script-like experience for experimentation similar to what Jupyter notebooks provide. Top-level statements are great for small console programs and utilities.
This is great for small, one-off scripts that can handle simple tasks for sysadmin work. I use Powershell for handling configuration changes on the CLI, but I don't write and save many scripts with it. Perhaps I need to learn more about the PS environment to fix that. Either way, I have a hunch that there are some tasks—which would be cumbersome in PS—that this new feature would make accessible.
https://docs.microsoft.com/en-us/archive/msdn-magazine/2016/...
https://itnext.io/hitchhikers-guide-to-the-c-scripting-13e45...
C# 9 just makes it easier.
public static bool IsLetter(this char c) =>
c is >= 'a' and <= 'z' or >= 'A' and <= 'Z'; if (e is not null)
{
// ...
}I don't see a big win over
if (e != null) {...} if (!(e is Class)) {/*...*/}
Sometimes the ! gets visually lost in the extra parentheses. The `not` patterns should especially make it cleaner to write certain styles of DeMorgan substitutions (!a && !b to !(a || b) type things) in ways that will be easier to read.Given those big wins, they alone provide a useful context of some consistency of having the `not` operator even for "simple" cases like (e is not null).
I've been using pattern matching for around 8 years now and still love it.
> may cause the switch statement to devolve into if/else
What does that mean?