Here you can find a summary of the most important features that were released with c# 7.
This summary was made mainly for myself as a go to place in case I want to remember what I read.
The resources I recommend for having each item described in detail are the following:
[Pluralsight course on C# 7: First Look][Pluralsight-Csharp-7] by mister [Jesse Liberty][Jesse-Liberty]
[MSDN][MSDN]
Static Using
Before:
Now:
Tuples
The code written with tuples in previous .net frameworks can become very verbose and difficult to comprehend. Therefore a few improvements were done in c# 7 to overcome this.
Examples with tuples used as return values as literals and with named values:
Use tuples in dictionaries as keys
Deconstructing tuples
Tuples can be deconstructed during declarations by using the corresponding type or by using var, or by using local variables.
Example
Pattern Matching
They are brought as enhancements of two existing constructs:
Is expressions can have a patterns on the right hand side, not just types Case clauses in switch statements can now match on patterns and conditionals, not just constants Pattern Matching in Is expressions:
Pattern Matching in Case clauses:
Local Functions
Functions declared within another function are now supported.
The main usage for this feature would be to have a helper method inside the function they help.
I just hope no one will get to use this. The legacy code that has to be maintain and understood nowadays contains enough complex, big methods.
I would recommend to stick with the clean code principles, and try to keep the code base as simple as possible.
Out Variables Literals
Before:
Out variables had to be declared before calling the method, but without using the var to declare them.
Example:
Now:
The variables can be declared inside the calling method.
Example:
Ref. Returns
The value types can be converted into reference values by using the “ref” keyword.
Use Exceptions as Expressions
Other Good References