C# 7.1 Features
In the previous article we have looked in to the features of C# 7.0, in this article we will see the some of the features introduced in C# 7.1 and 7.2
C# 7.1 | August 2017 | .NET Framework 4.6.2 | Visual Studio 2017 version 15.3 |
Default literal expressions
When we declare the local function or variable or methods until C#7.0 we need to instantiate that in the code, but the newer version of C# not necessary to create a default type of that value.
In C# 7.0
In C# 7.1
Here we don’t want to specify the type of the function or variable, by default its taking.
Tuple Name inferred
The names of tuple elements can be inferred from tuple initialization in many cases.
In C# 7.0
In C# 7.1
Here we don’t want to give the name, its taking from the variable name itself.
Async and Await in Main method
The purpose of it is for situations where your main method calls one or more async methods directly. Prior to C# 7.1, you had to introduce a degree of ceremony to that main method.
In C# 7.1
Pattern Matching with Generics
We have already got enough information about Pattern matching in C# 6.0 itself, now in C# 7.0 added some additional feature like “Pattern Matching with Generics”, in the previous version there is a design flow in the pattern matching with switch case statement.
Here the compiler indicates an error, because we cannot match the pattern with generics, so in order to avoid the problem in the next version introduced the feature.
C# 7.2 Features
Private Protected
This is the new access modifier in C#, previously we had private, public, protected and so on, this feature is enable the possibility to access the private member from the parent class and that too within the same assembly.
Non-trailing named arguments
In C# 4.0 a new type of argument is introduced known as a named parameter. Using this feature, we can specify the value of a parameter by parameter name regardless of its ordering in the method.
Here we can give the parameter in any order with the specified named parameter.
Leading underscores in numeric literals
The implementation of support for digit separators in C# 7.0 didn’t allow them _ to be the first character of the literal value. Hex and binary numeric literals may now begin with an _.
Reference semantics with value type
out: option to set the value
ref: Should set the value before passing it.
in: This method does not modify the value of the argument used as this parameter.
The “in” keyword specifies that you are passing the parameter by reference and the called method does not modify the value passed to it.
Conclusion
I hope this article will help much to understand the features of C# 7.1 and 7.2.
Very helpful and Great information,
I appreciate advise especially coming from a professional.
Thanks again and keep up the great work!