DEV Community

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

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