DEV Community

Cover image for Great new features in C# for a returning .NET dev

Great new features in C# for a returning .NET dev

Chris Noring on March 02, 2020

Follow me on Twitter, happy to take your suggestions on topics or improvements /Chris So I've been out of the loop for a while. I've actually bee...
Collapse
 
canro91 profile image
Cesar Aguirre

Great! I like tuples and records. Another feature I like is inline variable declaration with out parameters. I think for pattern matching, sometimes casting isn't needed, for example if (character is Hero h). I would like to read this kind of posts for Php.

Collapse
 
softchris profile image
Chris Noring

thank you for your comment Cesar. Appreciate you sharing your likes as well. Not a Php dev I'm afraid

Collapse
 
euantorano profile image
Euan T

Record types are one of my most highly anticipated features having used them in Kotlin (where they are known as data classes). Cutting out the Equals/GetHashCode boilerplate will be extremely useful.

The switch expression from C# 8 has been one of my most used new features since updating, the only disadvantage is that when you have multiple branches that should have the same resulting value you have to provide each branch separately rather than batching them together. Ideally I’d like to write something like:

return x switch {
    1, 2, 3 => β€œresult”,
    4, 5, 6 => β€œ...”
}

Another handy recent addition from C# 8 are indices and ranges: docs.microsoft.com/en-us/dotnet/cs... - I’ve found these especially useful when working with the Span<T> types!

Collapse
 
softchris profile image
Chris Noring

about your switch there I believe if you just write it like so (1,2,3) => "result", you can achieve what you want.. Thanks for sharing Euan

Collapse
 
t4rzsan profile image
Jakob Christensen

Good writeup, Chris. I am very much looking forward to record types and I hope that Microsoft will keep bringing good functional ideas from languages such as F# into C#.

Collapse
 
softchris profile image
Chris Noring

thank you Jacob :)

Collapse
 
theonlybeardedbeast profile image
TheOnlyBeardedBeast

Really thanks for this article, great!

Collapse
 
softchris profile image
Chris Noring

Thank you

Collapse
 
zakwillis profile image
zakwillis

Need to read this again at some point. Hence the bookmark. Am thinking most of this is useful when using the C# interactive mode?

Collapse
 
softchris profile image
Chris Noring

Could be. I mean evaluating pattern matching, I can see how that can be useful... or Deconstruct an object.. :)

Collapse
 
zakwillis profile image
zakwillis

Have bookmarked it - so when I have a chance will have a play around. Cheers.

Collapse
 
mteheran profile image
Miguel Teheran

I like C# but I have to confess that I prefer how to destructing in JS works than C#. it is very simple and you don't have to make a lot of effort to achieve it.

Collapse
 
softchris profile image
Chris Noring

thank you for your feedback Miguel. I agree with this in principle, it should be easy. It would surprise me a lot though if the C# team wasn't trying to improve this over time..

Collapse
 
cristiancastrodc profile image
cristiancastrodc

As always, you wrote an excellent article. Thanks!

Collapse
 
softchris profile image
Chris Noring

thank you cristian, appreciated :)