This is based on an email I send my .NET team at work
It appears to have been almost 2 months since I last sent one of these. My apologies for the laziness. I’m sure you wait every Friday with bated breath for a happy little notification in your email client.
Lets talk briefly about a few more new features in C#-7, which you can use today in VS2017.
A literal is a funny language designer term for a value specified directly in
source code, like
In case you were ever using large integers, you should be happy to know you can now place underscores anywhere in the number and have it ignored by the compiler.
This is a small feature, and I guess its nice.
I actually got bitten by a bug just yesterday where I could have been saved with
this. I couldn’t figure out why my math was always turning out to be off by a
factor of 10. It took me a minute to realize I had
const int MAX = 10000
const int MAX = 1000.
Digit separators might have made it more obvious:
const int MAX = 10_000 is a
little more distinguishable from
const int MAX = 1_000.
Here’s the feature proposal for your entertainment: https://github.com/dotnet/roslyn/issues/216
Oh, and they also added binary literals. This is for when you need to specify bit patterns directly, and is a little bit nicer than hex codes.
Combine it with the digit separator feature to split out the different bytes.
As primarily web programmers, we probably won’t run into much need for binary
literals, but they’re nice to have for infuriating the rest of your team.
Replace all the numbers in your application with binary literals: they might
enjoy the challenge of translating them. And if they’re one of the
10 types of
people who can’t read binary, they don’t deserve to be on a team of such high
caliber developers as you.
Here’s the feature proposal: https://github.com/dotnet/roslyn/issues/215
This is not a feature you would use directly, but certain library authors would be happy to have it.
Normally async methods have to return
Task<T>. This feature lets
those methods return any type of object that quacks like
I’m not sure of the specifics, but there are probably a couple of methods you
have to implement like
The main purpose was to allow the creation of
Task<T>, this async return type is a
struct not a
Thus there is no dynamic memory allocation or garbage collection. In some
high performance scenarios, this can reduce GC pauses.
ValueTask you’ll need to load this nuget package:
This change probably won’t effect your day to day. If a library starts using
ValueTask you probably wouldn’t even notice, since it works the same way as
Just be aware.
Here’s the implementation of
Here’s one of the proposals for the feature: https://github.com/dotnet/roslyn/issues/7169
In previous versions of C# the
throw keyword was always a statement. This meant
it had to be used on a line of its own which made certain patterns annoying.
Now, it can be an expression in some contexts.
For example, in assignment:
Previously you would need an
if statement to check the parameter for
like this feature, it will make parameter validations a lot cleaner.
Here’s the initial proposal: https://github.com/dotnet/roslyn/issues/5143
Next time we talk about Tuples, a much bigger change to the language. Stay tuned.