Efficiency and productivity of members of expressed functions in C # 6.0

In the new C # 6.0, we can define methods and properties using lambda expressions.

For example, this property

public string Name { get { return First + " " + Last; } } 

can be defined as follows:

 public string Name => First + " " + Last; 

Information about the function members that are in the phrase can be found here: http://blogs.msdn.com/b/csharpfaq/archive/2014/11/20/new-features-in-c-6.aspx

Does anyone know if there is overhead when using the new syntax? Could this slow down (or increase efficiency) the application, or maybe it doesn’t matter?

+26
Feb 09 '15 at 13:53 on
source share
3 answers

In the new C # 6.0, we can define methods and properties using lambda expressions.

No, you can’t. You can define the bodies of methods and properties using syntax that looks like a lambda expression because it uses the token => .

However, importantly, this does not mean that there is a delegate type. (Whereas a lambda expression is only allowed in the context where it is converted to an expression tree or delegate type.)

This is pure syntactic sugar. Your two code snippets will be compiled with the same IL. This is just another way of representing the body of a getter or method.

+55
Feb 09 '15 at 13:58
source share

They compile to the same IL, you can always check it yourself by doing this and using ildasm to extract the IL.

+7
Feb 09 '15 at 13:58
source share

This syntax makes it easier to write elements in the style of a lambda expression. This is the only difference.

0
Jul 01 '16 at 17:52
source share



All Articles