C# 7


All C# 7.0 features

Below you can find the list of all features introduced in C# 7. Tuples Deconstruction Out variables Patterns Discards Literal improvements Local functions Expression-bodied members Throw Expressions Ref returns and ref locals Generalized async return types


C# 7.0 – Ref returns and ref locals

Returning reference instead of value might be very useful – especially when one has to deal with big structures. C# allows passing parameters by reference, but a method was not able to return a reference. This has been changed with C# version 7.0.


C# 7.0 – Throw Expressions

Before C# 7.0 it was not possible to throw an exception directly in expression-bodied members. The workaround was to call a method that throws an exception.


C# 7.0 – Local functions

There are situations when one needs a small helper method, but it’s not quite obvious where to put it. The method might not be generic enough to expose it as a new entity or even as a class member.


C# 7.0 – Discards

Sometimes there is a need to ignore a result of a method. It’s straightforward if that’s a return value – just don’t assign it. But what should be done in other cases?


C# 7.0 – Patterns

The concept of patterns was introduced in C# 7.0. The idea is to check if an object reflects a specified shape.


C# 7.0 – Out variables

Using out parameters was always a bit painful. The biggest drawback is the need to declare variables before they can be used.