C# 9
C# 9 Cheat Sheet with code example.
Records


Init only setters
Top-level statements
Pattern matching enhancements
Native sized integers
Function pointers
Suppress emitting localsinit flag
Target-typed new expressions
static anonymous functions
Target-typed conditional expressions
Covariant return types
Extension GetEnumerator support for foreach loops
Lambda discard parameters
Attributes on local functions
Module initializers
New features for partial methods
Download it Powerpoint or PDF:
https://github.com/alugili/CSharp-9-CheatSheet
Hell yeah, thank you for this!
On one of the last sections the title says GetEmurator().
Watch out for those emus though… I hear they’re good at starting wars
Super neat format, really concise and straight to the point. 🙂
Thanks a lot for sharing !
It’s going to be useful.
Am I the only one that sees 8 pixels?
The JPG seems compressed beyond readability. Look at the PDF on GitHub.
Excellent work. Thank you.
You had me at
why does it look like some obscene emoticon
Dude this is awsome. Thanks.
A new C# type is immutable by default.
Did you mean “A new C# type that is immutable by default.”?
Edit: Also, “GetEmurator” :p
Also “make [it] more performance” at the bottom left
How can I enable C# 9 features/compilation for a .NET Standard 2.0 library? Great cheat sheet btw!
Change the LangVersion in your .csproj to 9.0. You will be able to use most of the C#9 features as long as you’re using an updated Roslyn compiler e.g. the one in recent versions of VS2019.
The only features you won’t be able to use are the ones baked into the runtime and those are probably not the ones you’re looking to use anyway. You can read online about the few features that you’d miss.
Happy coding with C#9
You can’t officially, but if you Google around there are several guides. Only some (most) of the features can be used.
I’m assuming this will be in .NET 5.0?
Pretty cool stuff, I like the new record type, I use named tuples but this will be even cleaner I think.
Records are reference types, though, where value tuples are value types, which can be important.
Very nice!!
Extended partial methods look interesting.
Was confused at first on how a public partial T Do(...); would work but looks like it’s a complication error to not implement a partial method that’s defined in the old style (the partial void Do(...) style).
So similar to falling to implement an abstract method, but for a different purpose.
Nice work, pdf looks great.
Can you export the images as a (larger) png instead of jpg? The jpg is not readable.
Page 4 has a section called “GetEmurator” and it’s meant to be “GetEnumerator”.
Um how do you upgrade your C# version? I’ve been stuck on 7.3 this whole time
In your .csproj file, in the same <PropertyGroup> as your <TargetFramework>, include <LangVersion>9.0</LangVersion>.
I’ve used TargetFramework values of netstandard2.1 and net5.0 with this successfully.
C# devs
null reference exceptions

source