Today we are going to explore yet another new feature of C# 6.0 which will be coming in this release. This is my fifth post in the series of C# 6.0 New Features. Don't forget to read my previous post in this Series :
In C# 6.0 Microsoft has included yet another great feature called as "Expression-bodied Function" and to explore and experience more about that you need to download Visual Studio 2015 and .NET Framework 4.6.
Expression-bodied function allows properties, methods, operators and other functions to have bodies just like Lambda expressions instead of blocks of statements, thus reducing lines of codes and becomes more readability. But from my experience there are many Developers who still prefers writing code in the old fashion because according to them it’s clearer and less confusing. Anyways it all comes to the personal choice.
So now in C# 6.0 instead of writing the whole property body using getters and setters, Developer can now just use the lambda operator (=>) to return values. Below is the example.
And very similar to property, you can use Expression Bodied function to methods which returns value to the caller. Below is the example.
Developer can use this feature even for methods returning void as well as Task returning async. Syntax remains the same as above example.
How exactly it will be beneficial is still a question but it will definitely reduce the line of codes, which I am sure some would prefer and some would not.
Today we are going to explore yet another new feature of C# 6.0 which will be coming in this release. This is my fourth post in the series of C# 6.0 New Features. Don't forget to read my previous post in this Series :
Today we will be learning about String Interpolation/String Concatenation with respect to C# 6.0.
String Concatenation - It's used to join the different records to the users and to accomplish this we either use "+" symbol or string.Format method to format and to organize it. With the new release of C# 6.0, it's now a old mechanism.
But now with C# 6.0, Developer can directly put expressions in the string literal to show the values in proper format and you can even align or specify different format to your values. And one of the best is, Developer can write conditions within string literals with additional strings as content.
Below are the few examples :
Hope you like this feature and since Microsoft is yet to release the stable version of Visual Studio 2015 and C# 6.0, so you can expect quite a lot more feature in String Interpolation. Stay tune to my series of post on C# 6.0 Features. Happy Coding.