You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$10
For Premium members:
In this article, I will provide information about Expression Bodied Functions and Properties including how they work.
IntroductionIn November 2014 Microsoft introduced the latest version of the Visual Studio. This latest version is known as the Visual Studio 2015 preview. In this new version of Visual Studio Microsoft introduced many new features and enhancements of C# 6.0. In C# 6.0 Microsoft added many new features that are very useful for developers and that make programming easier for developers. One of the features is Expression Bodied Functions and Properties that is very useful feature for C# 6.0 programmers. C# 6.0 is the latest version of the C# language that makes some new changes in it. It includes many new features in it. I will explain for you the Expression Bodied Functions and Properties feature.Expression Bodied Functions and PropertiesExpression Bodied Functions and Properties is the latest feature of C# 6.0. The main advantage is the use of expression bodies to reduce the code. Using expression bodies you can create the expression bodies for the function/method, property and reduce the code. If you are familiar with lambda expressions then expression bodies are similar to lambda expressions in C#. As we know lambda expressions use functions and are called by a delegate and Expression bodies are similar to lambda expression functions.Before getting to body expression methods in C# 6.0 you must write a method many times for some lines of code, but now using expression body members you can do that easier and in a single line of code. Using expression bodies you reduce the code and here you do not want the use of curly braces. In simple words I want to say that the code that you have written in the { } (curly brasses) has been altered with the =>, please read to see the example. Using this example you can easily understand the scenario. But here one thing to remember is that here => does not work as a lambda operator so here the compiler does not covert this into a delegate type. It is just like a formatting pattern to reduce the code.I tell you how to convert a property, an operator and a method with the expression bodies.Nothing new in the beginning. Just open your Visual Studio 2015, create a new project, select the language C#, select the console application and write the code depending on your needs.Example PropertyIn this example we just only create a property in the Visual Studio 2015 using C# code and tells you how to reduce the code of the statement using the expression bodies member method.This code is simple. It declares a property and gets its value.Code
Code
Programming Strings using C#